Advertisement
YEZAELP

CUBE-158: Square Prime

Aug 7th, 2020
90
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector <bool> prime(1e3+1,true);
  4. int main(){
  5.  
  6.     int a,b;
  7.     scanf("%d%d",&a,&b);
  8.  
  9.     set <int> square_prime;
  10.     prime[0] = false;
  11.     prime[1] = false;
  12.     for(int i=2;i<=1e3;i++){
  13.         if(prime[i] == true){
  14.             square_prime.insert(i*i);
  15.             for(int j=i+i;j<=1e3;j=j+i){
  16.                 prime[j] = false;
  17.             }
  18.         }
  19.     }
  20.  
  21.     bool found = false;
  22.     for(int i=a;i<=b;i++){
  23.         if(square_prime.find(i) != square_prime.end()) {
  24.             printf("%d ",i);
  25.             found = true;
  26.         }
  27.     }
  28.     if(!found) printf("-1");
  29.  
  30.     return 0;
  31. }
  32.  
Advertisement
RAW Paste Data Copied
Advertisement