Advertisement
shanto420

twin prime

Oct 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. #include<algorithm>
  4.  
  5. long long int a[20000000];
  6. using namespace std;
  7. int main(){
  8. long long int i,j,k,m,n,p,r,l=0;
  9.  
  10. scanf("%lld",&n);
  11.  
  12. fill(a,&a[20000000],-1);
  13.  
  14. for(i=2;i<20000000;i++)
  15. {
  16. if(a[i]==-1)
  17. {
  18. for(j=2;i*j<20000000;j++)
  19. {
  20. a[i*j]=0;
  21. }
  22. }
  23. }
  24. for(i=2;i<20000000;i++)
  25. {
  26. if(a[i]!=0)
  27. {
  28. a[i]=i;
  29. // printf("%d\n",a[i]);
  30.  
  31. }
  32. }
  33. sort(a,a+20000000);
  34. /* for(i=0;i<200;i++)
  35. {
  36. printf("%lld\n",a[i]);
  37. }*/
  38.  
  39. for(i=2;i<20000000;i++)
  40. {
  41. if(a[i]>0&&(a[i]-a[i+1])==-2)
  42. {
  43. l++;
  44. }
  45. if(n==l)
  46. {
  47. printf("(%lld, %lld)\n",a[i],a[i+1]);
  48. break;
  49. }
  50.  
  51. }
  52.  
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement