Topic Connection: Hdu_5750_dertouzos
Test instructions
Give you a N, a D, ask you how many of the numbers in the small number of n is the largest factor of D, such as 6 has a factor 1 2 3 the largest is 3
Exercises
At that time, the game did not consider the optimization of the constant, after the first Test, and then FST, lying trough ...
Careful observation of the problem can be found we only need to find a number s,s*d is smaller than N, and S is not greater than the smallest qualitative factor of d, in order to make s*d the largest factor of this number is D. Then we use the linear sieve first to sift out the prime of 2W, in fact, should be screened to 33333, but I tested the data 2W can also pass, and then just sweep the line
1#include <cstdio>2 #defineF (I,A,B) for (int i=a;i<=b;++i)3 4 intprimes[30000],tot=0, n=20000;5 BOOLvis[20001];6 voidEuler () {7F (I,2, N) {8 if(!vis[i]) primes[++tot]=i;9F (J,1, tot) {Ten if(i*primes[j]>n) Break; Onevis[i*primes[j]]=1; A if(i%primes[j]==0) Break; - } - } the } - intMain () { - Euler (); - intt,n,d; +scanf"%d",&t); - while(t--) + { Ascanf"%d%d",&n,&d); at intmi=-1, tp= (n1)/d,ans=0; - for(intI=1; i<tot;i++) - { - if(PRIMES[I]>TP) Break; -ans++; - if(d%primes[i]==0) Break;//If D is a multiple of the current prime number, then the next prime number is definitely larger than the prime number, so exit directly in } -printf"%d\n", ans); to } + return 0; -}View Code
Hdu_5750_dertouzos (linear sieve)