Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- vector<int>primes;
- vector< vector< int > > v;
- bool chk[100000];
- int setcnt[100000];
- void seive()
- {
- chk[0]=true;
- chk[1]=true;
- for(int i=2;i<50000;i++){
- if(chk[i]) continue;
- primes.push_back(i);
- for(int j=2;i*j<50000;j++){
- chk[i*j]=true;
- }
- }
- }
- void sets()
- {
- vector<int>h;
- v.push_back(h);
- int cnt=1,k=0,i=0,x;
- while(i<primes.size()-100){
- if(primes[i+1]-primes[i]==primes[i+2]-primes[i+1]){
- x = primes[i];
- while(k<=x){
- setcnt[k++]=cnt;
- }
- vector<int>temp;
- temp.push_back(primes[i]);
- temp.push_back(primes[i+1]);
- temp.push_back(primes[i+2]);
- i+=3;
- while(primes[i]-primes[i-1]==primes[i-1]-primes[i-2]){
- temp.push_back(primes[i]);
- i++;
- }
- i--;
- x = primes[i];
- while(k<x){
- setcnt[k++]=-cnt;
- }
- cnt++;
- v.push_back(temp);
- }
- else{
- i++;
- }
- }
- }
- int main()
- {
- //read();
- //write();
- seive();
- sets();
- int x,y;
- while(cin>>x>>y){
- if(x==0 && y==0) break;
- if(x>y) swap(x,y);
- x = setcnt[x];
- y = setcnt[y];
- if(x<0){
- x=-x;
- x++;
- }
- if(y<0) y=-y;
- for(int i=x;i<y;i++){
- for(int j=0;j<v[i].size();j++){
- if(j) cout<<' ';
- cout<<v[i][j];
- }
- cout<<'\n';
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement