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)