Advertisement
erfanul007

UVa 11287

Jun 1st, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5.  
  6. #define read() freopen("input.txt", "r", stdin)
  7. #define write() freopen("output.txt", "w", stdout)
  8.  
  9. bool checkPrime(ll n)
  10. {
  11. for(ll i=2;i*i<=n;i++){
  12. if(n%i==0) return false;
  13. }
  14. return true;
  15. }
  16.  
  17. ll BigMod(ll base,ll power,ll mod)
  18. {
  19. ll res = 1;
  20. base = base%mod;
  21. while(power>0){
  22. if(power%2)
  23. res = (res*base)%mod;
  24. power/=2;
  25. base = (base*base)%mod;
  26. }
  27. return res;
  28. }
  29.  
  30. int main()
  31. {
  32. //read();
  33. //write();
  34. ll a,p,x;
  35. while(cin>>p>>a && p && a){
  36. if(checkPrime(p)){
  37. cout<<"no\n";
  38. continue;
  39. }
  40. x = BigMod(a,p,p);
  41. if(x==a) cout<<"yes\n";
  42. else cout<<"no\n";
  43. }
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement