标签:
1 #include <iostream> 2 #include <queue> 3 #include <stack> 4 #include <cstdio> 5 #include <vector> 6 #include <map> 7 #include <set> 8 #include <bitset> 9 #include <algorithm> 10 #include <cmath> 11 #include <cstring> 12 #include <cstdlib> 13 #include <string> 14 #include <sstream> 15 #define lson l,m,rt*2 16 #define rson m+1,r,rt*2+1 17 #define mod 1000000007 18 #define INF 1000000006 19 using namespace std; 20 typedef long long LL; 21 int n,d,k,p; 22 vector<LL> Q; 23 bool vis[1000000+5]; 24 void init() 25 { 26 for(LL i=2;i<=1000000+5;i++) 27 { 28 if(!vis[i]) 29 { 30 Q.push_back(i); 31 for(LL j=i*i;j<=1000000+5;j+=i) 32 { 33 vis[j]=true; 34 } 35 } 36 } 37 } 38 int main() 39 { 40 #ifdef Local 41 freopen("data.txt","r",stdin); 42 #endif 43 int T,i,j,h,r,sum=0,m,ans,flag,q,mid,l; 44 cin>>T; 45 init(); 46 while(T--) 47 { 48 ans=flag=0; 49 scanf("%d%d",&n,&d); 50 n=(n-1)/d; 51 for(i=0;Q[i]<=n&&i<Q.size();i++) 52 { 53 ans++; 54 if((d%Q[i])==0)break; 55 } 56 cout<<ans<<endl; 57 } 58 }
标签:
原文地址:http://www.cnblogs.com/27sx/p/5699967.html