Advertisement
Barbie10

Xprime

Jan 24th, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  5. #define int long long int
  6. #define forn(i,n) for(int i=0;i<n;i++)
  7. #define pb push_back
  8. #define ff first
  9. #define ss second
  10. const int M = 1e9 + 7;
  11.  
  12. const int N = 9e7;
  13. bool sieve[N];
  14.  
  15. void solve()
  16. {  
  17.    
  18.    
  19.     sieve[0] = sieve[1] = 1;
  20.    
  21.     for(int i = 2; i*i<=N; i++)
  22.     {
  23.         if(!sieve[i])
  24.         {
  25.             for(int j = i*i; j<N; j+=i )
  26.             sieve[i] = 1;
  27.         }
  28.     }
  29.    
  30.     int t;
  31.     cin>>t;
  32.     while(t--)
  33.     {
  34.         string num;
  35.         cin>>num;
  36.         //cout<<num<<" ";
  37.         int size = num.length();
  38.         //cout<<num;
  39.        // cout<<size<<" ";
  40.        int x = stoi(num);
  41.         //cout<<x<<" ";
  42.        if(!sieve[x])
  43.         {
  44.             cout<<"yes\n";
  45.             break;
  46.         }
  47.        
  48.        
  49.        /* if(num == 1000000)
  50.         {
  51.             cout<<"no\n";
  52.             break;
  53.         }
  54.         */
  55.         int cnt = 0;
  56.        
  57.         for(int j = 1; j<=9; j++)
  58.         {
  59.             num[0] = (char)j;
  60.             x = stoi(num);
  61.             if(!sieve[x])
  62.             {
  63.                 cnt++;
  64.             }
  65.         }
  66.        
  67.         for(int i = 1; i<size; i++)
  68.         {
  69.             for(int j = 0; j<=9; j++)
  70.             {
  71.                 num[i] = (char)j;
  72.                 x = stoi(num);
  73.                 if(!sieve[x])
  74.                 {
  75.                     cnt++;
  76.                 }
  77.             }
  78.         }
  79.        
  80.         if(cnt == 1)
  81.         cout<<"yes\n";
  82.         else
  83.         cout<<"no\n";
  84.        
  85.        
  86.     }
  87.    
  88.    
  89.     return;
  90. }
  91.  
  92. signed main()
  93. {   IOS
  94.    
  95.     solve();
  96.     return 0;
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement