Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- #define int long long int
- #define pb push_back
- #define ff first
- #define ss second
- const int mod = 1e9 + 7;
- const int N = 1e6+1;
- bool solve(int &n, vector<int> &primes){
- if(n%2 == 1 || primes[n]){
- return true;
- }
- else{
- n = n - n%10;
- for(int i = 1; i < 10; i+=2){
- if(primes[n+i]){
- return true;
- }
- }
- }
- return false;
- }
- signed main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- vector<int> primes(N, 1);
- primes[0] = primes[1] = 0;
- for(int i = 2; i < N; i++){
- if(primes[i] == 1 && i * i <= N){
- for(int j = i*i; j < N; j+=i){
- primes[j] = 0;
- }
- }
- }
- int t;
- cin>>t;
- while(t--){
- int n;
- cin>>n;
- if(solve(n, primes)){
- primes[n] = 1;
- cout<<"yes"<<"\n";
- }
- else{
- cout<<"no"<<"\n";
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment