Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- #define read() freopen("input.txt", "r", stdin)
- #define write() freopen("output.txt", "w", stdout)
- bool checkPrime(ll n)
- {
- for(ll i=2;i*i<=n;i++){
- if(n%i==0) return false;
- }
- return true;
- }
- ll BigMod(ll base,ll power,ll mod)
- {
- ll res = 1;
- base = base%mod;
- while(power>0){
- if(power%2)
- res = (res*base)%mod;
- power/=2;
- base = (base*base)%mod;
- }
- return res;
- }
- int main()
- {
- //read();
- //write();
- ll a,p,x;
- while(cin>>p>>a && p && a){
- if(checkPrime(p)){
- cout<<"no\n";
- continue;
- }
- x = BigMod(a,p,p);
- if(x==a) cout<<"yes\n";
- else cout<<"no\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement