#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
int ipow(ll b, int e, int mod){
int ret = 1;
for(; e; e >>= 1){
if(e & 1) ret = ret * b % mod;
b = b * b % mod;
}
return ret;
}
const int ptst = 4;
int p[ptst] = {2, 3, 5, 7};
bool ptest(int x){
if(x < 4) return x > 1;
for(int i = 0; i < ptst; i++) if(x % p[i] == 0) return 0;
int y = x - 1, e = __lg(y & -y);
y >>= e;
for(int i = 0; i < ptst; i++){
ll z = ipow(p[i] % x, y, x);
if(z == 1) continue;
for(int i = 0; i < e && z != x - 1; i++) z = z * z % x;
if(z != x - 1) return 0;
}
return 1;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout << ptest(1000000007) << endl;
cout << ptest(1350451049) << endl;
cout << ptest(1000696969) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIGVuZGwgJ1xuJwojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIHBpIHBhaXI8aW50LCBpbnQ+CiNkZWZpbmUgZiBmaXJzdAojZGVmaW5lIHMgc2Vjb25kCgppbnQgaXBvdyhsbCBiLCBpbnQgZSwgaW50IG1vZCl7CglpbnQgcmV0ID0gMTsKCWZvcig7IGU7IGUgPj49IDEpewoJCWlmKGUgJiAxKSByZXQgPSByZXQgKiBiICUgbW9kOwoJCWIgPSBiICogYiAlIG1vZDsKCX0KCXJldHVybiByZXQ7Cn0KCmNvbnN0IGludCBwdHN0ID0gNDsKaW50IHBbcHRzdF0gPSB7MiwgMywgNSwgN307CmJvb2wgcHRlc3QoaW50IHgpewoJaWYoeCA8IDQpIHJldHVybiB4ID4gMTsKCWZvcihpbnQgaSA9IDA7IGkgPCBwdHN0OyBpKyspIGlmKHggJSBwW2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