Saleh127

UVA 11287

Jul 20th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define fellow_junior ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. ll mod(ll a,ll c,ll m)
  7. {
  8. if(c==0) return 1;
  9. ll x=mod(a,c/2,m);
  10. x=(x*x)%m;
  11. if(c%2==1)
  12. {
  13. x=(x*a)%m;
  14. }
  15. return x;
  16. }
  17. ll prime(ll p)
  18. {
  19. ll d=sqrt(p),i;
  20. for(i=2;i<=d;i++)
  21. {
  22. if(p%i==0)
  23. {
  24. return 0;
  25. break;
  26. }
  27. }
  28. return 1;
  29. }
  30. int main()
  31. {
  32. fellow_junior
  33. ll p,a,i,j,k;
  34. while(cin>>p>>a && p &&a)
  35. {
  36. j=prime(p);
  37. if(j==1)
  38. {
  39. cout<<"no"<<endl;
  40. continue;
  41. }
  42. k=mod(a,p,p);
  43. if(k==a)
  44. {
  45. cout<<"yes"<<endl;
  46. }
  47. else cout<<"no"<<endl;
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment