Sentiment: This is another zimpha huge problem, then 04 successful FST (that is, the problem)
In fact, too young, trying to increase posture,
Analysis: Direct enumeration of these numbers is not good enumeration, another angle, enumeration x*d, that is, the second multiplier of D is how much
Obviously X<=min (d, (n-1)/d), X is also prime, and finally found that x must be less than the minimum factor of D
The prime number within 10w is then preprocessed, and then each time K=min (d, (n-1)/d) is first obtained, and then the D minimum factor is less than K
The key to the problem is to find the minimum factor of D, I am violent looking (and then hit all the big primes on the T)
In fact, when D is a large prime number, K is small, direct enumeration of prime numbers, if greater than K has not, you do not have to find (anyway to the smallest)
After the game, this one limit is over.
Spit Groove: Still Young
#include <stdio.h>#include<iostream>#include<algorithm>#include<string.h>#include<vector>#include<math.h>#include<stack>#include<map>#defineX First#defineY Secondusing namespaceStd;typedefLong LongLL;Const intN = 1e5+5;Const intINF =0x3f3f3f3f; typedef pair<int,int>PII;BOOLVis[n];intPrime[n>>1],tot;voidGetprime () { for(intI=2; i*i<=n-5;++i) { if(Vis[i])Continue; for(intj=i*i;j<=n-5; j+=i) vis[j]=true; } for(intI=2; i<=n-5;++i)if(!vis[i]) prime[++tot]=i;}intMain () {getprime (); intT; scanf ("%d",&T); while(t--){ intn,d; scanf ("%d%d",&n,&d); intTmp=min (d, (n1)/d); intflag=-1; for(intI=1; i<=tot&&prime[i]<=tmp&&1ll*prime[i]*prime[i]<=d;++i) { if(D%prime[i])Continue; Else{Flag=prime[i]; Break;} } if(flag==-1) flag=D; TMP=min (Tmp,flag); intK=lower_bound (prime+1, prime+1+TOT,TMP)-Prime; if(k==tot+1|| PRIME[K]>TMP)--K; printf ("%d\n", K); } return 0;}
View Code
HDU 5750 Dertouzos Simple Math