标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 int zj[5000000]; 7 int ssb[5000000],pn; 8 void f() 9 { 10 int i,j; 11 memset(zj,0,sizeof(zj)); 12 zj[0]=zj[1]=1; 13 pn=0; 14 for (i=2;i<=5000000;i++) 15 { 16 if (!zj[i]) {ssb[pn]=i;pn++;} 17 for (j=0;j<pn;j++) 18 { 19 if (i*ssb[j]>5000000) break; 20 zj[i*ssb[j]]=1; 21 if (i%ssb[j]==0) break; 22 } 23 } 24 } 25 int main() 26 { 27 int t,n,i,c; 28 f(); 29 scanf("%d",&t); 30 while (t--) 31 { 32 scanf("%d",&n); 33 for (i=0;i<pn;i++) 34 { 35 c=lower_bound(ssb,ssb+pn,ssb[i]+n)-ssb; 36 if (ssb[c]==ssb[i]+n) 37 { 38 printf("%d %d\n",ssb[c],ssb[i]); 39 break; 40 } 41 } 42 } 43 }
hdu 4715 Difference Between Primes (二分查找)
标签:
原文地址:http://www.cnblogs.com/pblr/p/4732532.html