muditjain

XPrime

Jan 25th, 2022 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  6. #define int long long int
  7. #define pb push_back
  8. #define ff first
  9. #define ss second
  10. const int mod = 1e9 + 7;
  11. const int N = 1e6+1;
  12.  
  13. bool solve(int &n, vector<int> &primes){
  14.     if(n%2 == 1 || primes[n]){
  15.         return true;
  16.     }
  17.     else{
  18.         n = n - n%10;
  19.         for(int i = 1; i < 10; i+=2){
  20.             if(primes[n+i]){
  21.                 return true;
  22.             }
  23.         }
  24.     }
  25.     return false;
  26. }
  27.  
  28. signed main()
  29. {
  30.     ios_base::sync_with_stdio(0);
  31.     cin.tie(0);
  32.     cout.tie(0);
  33.    
  34.     vector<int> primes(N, 1);
  35.     primes[0] = primes[1] = 0;
  36.     for(int i = 2; i < N; i++){
  37.         if(primes[i] == 1 && i * i <= N){
  38.             for(int j = i*i; j < N; j+=i){
  39.                 primes[j] = 0;
  40.             }
  41.         }
  42.     }
  43.    
  44.     int t;
  45.     cin>>t;
  46.    
  47.     while(t--){
  48.         int n;
  49.         cin>>n;
  50.         if(solve(n, primes)){
  51.             primes[n] = 1;
  52.             cout<<"yes"<<"\n";
  53.         }
  54.         else{
  55.             cout<<"no"<<"\n";
  56.         }
  57.     }
  58.    
  59.     return 0;
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
Add Comment
Please, Sign In to add comment