HDU 5317 RGCDQ (2nd of the third field of 2015 schools) Prime number playing table + prefix and subtraction suffix (DP)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5317

Test Instructions: F (x) indicates that the number of different qualitative factors of x results in finding the largest gcd in the L,r interval (f (i), F (j)), I, J in the L,r interval.

idea: because 2<=l < r<=1000000, so the number of their quality factor is 7, that is 1<=f (x) <=7, because the maximum gcd, so as long as you know in the L,r interval of each F (x) The results can be known.

Code:

1#include <stdio.h>2#include <string.h>3#include <iostream>4#include <algorithm>5 using namespacestd;6 7 Const intx=1000010;8 BOOLisprime[x+1];9 intTotal//CountTen intprime[79000]; One voidgetprime () A { -Total=0; -memset (IsPrime,true,sizeof(IsPrime)); thememset (Prime,0,sizeof(prime)); -      for(intI=2; i<=x;i++) -     { -         if(Isprime[i]) prime[total++]=i; +          for(intj=0; J<total && i*prime[j]<=x; J + +) -         { +isprime[i*prime[j]]=false; A             if(i%prime[j]==0) at                  Break; -         } -     } - } -  - intdp[x][9]; in intNum[x]; - voidGetcot () to { +memset (NUM,0,sizeof(num)); -      for(intI=0;p rime[i]<=1000000; i++) the          for(intj=prime[i];j<=1000000; j+=Prime[i]) *num[j]++; $ }Panax Notoginseng  - voidGao () the { +Memset (DP,0,sizeof(DP)); Adp[2][1]=1; the      for(intI=3; i<=1000000; i++) +     { -         intans=Num[i]; $          for(intj=1; j<=7; j + +) $dp[i][j]=dp[i-1][j]; -dp[i][ans]++; -     } the } - intMain ()Wuyi { the     intt,l,r,aa[Ten],ma; - getprime (); Wu Getcot (); - Gao (); Aboutscanf"%d",&T); $      while(t--) -     { -Ma=1; -scanf"%d%d",&l,&R); A          for(intI=1; i<=7; i++) +         { theaa[i]=dp[r][i]-dp[l-1][i]; -             if(aa[i]>=2&&i>Ma) $Ma=i; the         } the         if(aa[6]>0&&aa[3]>0) theMa=max (MA,3); the         Else if(aa[6]>0&&aa[2]>0|| aa[4]>0&&aa[2]>0) -Ma=max (MA,2); inprintf"%d\n", MA); the     } the     return 0; About}
View Code

HDU 5317 RGCDQ (2nd of the third field of 2015 schools) Prime number playing table + prefix and subtraction suffix (DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.