Advertisement
erfanul007

UVa 10650

Jun 1st, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define read() freopen("input.txt", "r", stdin)
  5. #define write() freopen("output.txt", "w", stdout)
  6.  
  7. vector<int>primes;
  8. vector< vector< int > > v;
  9. bool chk[100000];
  10. int setcnt[100000];
  11.  
  12. void seive()
  13. {
  14. chk[0]=true;
  15. chk[1]=true;
  16. for(int i=2;i<50000;i++){
  17. if(chk[i]) continue;
  18. primes.push_back(i);
  19. for(int j=2;i*j<50000;j++){
  20. chk[i*j]=true;
  21. }
  22. }
  23. }
  24.  
  25. void sets()
  26. {
  27. vector<int>h;
  28. v.push_back(h);
  29. int cnt=1,k=0,i=0,x;
  30. while(i<primes.size()-100){
  31. if(primes[i+1]-primes[i]==primes[i+2]-primes[i+1]){
  32. x = primes[i];
  33. while(k<=x){
  34. setcnt[k++]=cnt;
  35. }
  36. vector<int>temp;
  37. temp.push_back(primes[i]);
  38. temp.push_back(primes[i+1]);
  39. temp.push_back(primes[i+2]);
  40. i+=3;
  41. while(primes[i]-primes[i-1]==primes[i-1]-primes[i-2]){
  42. temp.push_back(primes[i]);
  43. i++;
  44. }
  45. i--;
  46. x = primes[i];
  47. while(k<x){
  48. setcnt[k++]=-cnt;
  49. }
  50. cnt++;
  51. v.push_back(temp);
  52. }
  53. else{
  54. i++;
  55. }
  56. }
  57. }
  58.  
  59. int main()
  60. {
  61. //read();
  62. //write();
  63. seive();
  64. sets();
  65. int x,y;
  66. while(cin>>x>>y){
  67. if(x==0 && y==0) break;
  68. if(x>y) swap(x,y);
  69. x = setcnt[x];
  70. y = setcnt[y];
  71. if(x<0){
  72. x=-x;
  73. x++;
  74. }
  75. if(y<0) y=-y;
  76. for(int i=x;i<y;i++){
  77. for(int j=0;j<v[i].size();j++){
  78. if(j) cout<<' ';
  79. cout<<v[i][j];
  80. }
  81. cout<<'\n';
  82. }
  83. }
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement