Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- //using segmented sieve of eranthroses
- typedef long long ll;
- //range of int -2*10^9 to 2*10^9
- //range of ll -9*10^18 to 9*10^18
- int main()
- { ios::sync_with_stdio(0);
- cin.tie(0);
- int rootN=sqrt(1000000000)+5;
- bool prime[rootN];
- memset(prime,1,sizeof(prime));
- int i=2;
- while(i<rootN)
- {
- if(prime[i])
- {
- int x=2*i;
- while(x<rootN)
- {
- prime[x]=0;
- x+=i;
- }
- }
- i++;
- }
- vector<int> primes;
- for(int i=2;i<rootN;i++)
- if(prime[i]) primes.emplace_back(i);
- // for(int x:primes) cout<<x<<" ";
- int t;
- cin>>t;
- while(t--)
- {
- ll m,n;
- cin>>m>>n;
- bool result[n-m+1];
- memset(result,1,sizeof(result));
- ll sqroot=sqrt(n);
- for(int i=0;primes[i]<=sqroot;i++)
- {
- ll x=max((ll)(2*primes[i]),primes[i]*(m/primes[i]));
- while(x<=n)
- {
- if(x>=m)
- result[x-m]=0;
- x+=primes[i];
- }
- }
- int i=0;
- if(m==1)i++;
- for( ;i<n-m+1;i++)
- if(result[i])cout<<i+m<<"\n";
- cout<<"\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment