Advertisement
Farjana_akter

Untitled

Aug 8th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool mark[100005]= {false};
  5. long long int k,isprime[100005];
  6. //vector<long long int>store;
  7.  
  8. void sieve()
  9. {
  10. long long int i,j,m;
  11. mark[0]=true;
  12. mark[1]=true;
  13. for(i=2; i*i<=100000; i++)
  14. {
  15. if(mark[i]==false)
  16. {
  17. for(j=i*i; j<=100000; j+=i)
  18. mark[j]=true;
  19. }
  20. }
  21. k=0;
  22. for(i=2; i<=100000; i++)
  23. {
  24. if(mark[i]==false)
  25. isprime[k++]=i;
  26. }
  27. //for(m=0;m<10;m++)
  28. // cout<<isprime[m]<<" ";
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. //freopen("in.txt","r",stdin);
  35. //freopen("out.txt","w",stdout);
  36. sieve();
  37. long long int x,y,i=0,m,j,cnt,dif;
  38. while(cin>>x>>y)
  39. {
  40. if(x==0 && y==0)
  41. break;
  42. if(x>y)
  43. swap(x,y);
  44. i=0;
  45. vector<long long int>store;
  46. while(1)
  47. {
  48. cnt=0;
  49. if(isprime[i]>y)
  50. break;
  51.  
  52. dif=isprime[i+1]-isprime[i];
  53. j=i+1;
  54. store.push_back(isprime[i]);
  55. store.push_back(isprime[i+1]);
  56. // for(m=0; m<store.size(); m++)
  57. // cout<<store[m]<<" ";
  58. // cout<<endl;
  59. while(isprime[j+1]-isprime[j]==dif)
  60. {
  61. store.push_back(isprime[j+1]);
  62. cnt++;
  63. j++;
  64. }
  65. // cout<<"after while"<<endl;
  66. // for(m=0; m<store.size(); m++)
  67. // cout<<store[m]<<" ";
  68. // cout<<endl;
  69. if(!cnt)
  70. {
  71. i++;
  72. store.clear();
  73. }
  74. else
  75. {
  76. i=j;
  77. if(store[store.size()-1]>y)
  78. continue;
  79. if(store[0]<x)
  80. continue;
  81. for(m=0; m<store.size(); m++)
  82. {
  83. if(m) cout<<' ';
  84. cout<<store[m];
  85. }
  86. cout<<endl;
  87. store.clear();
  88. }
  89. }
  90. }
  91. return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement