SuitNdtie

Square Prime

May 1st, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<vector>
  3. typedef long long int ll;
  4. using namespace std;
  5.  
  6. bool sieve[1000010];
  7. int main()
  8. {
  9.     vector<ll> vec;
  10.     int cnt = 0;
  11.     for(ll i = 2 ; i <= 1000000 ; i ++){
  12.         if(!sieve[i]){
  13.             vec.push_back(i*i);
  14.             for(ll j = i*2; j <= 1000000 ; j += i){
  15.                 sieve[j] = true;
  16.             }
  17.             cnt++; 
  18.         }
  19.        
  20.     }
  21.     ll L,R;
  22.     scanf("%lld %lld",&L,&R);
  23.     bool check = false;
  24.     for(int i = 0 ; i < vec.size() ; i ++){
  25.         if(L <= vec[i] && vec[i] <= R){
  26.             printf("%lld ",vec[i]);
  27.             check = true;
  28.         }
  29.     }
  30.     if(!check)printf("-1");
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment