codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<utility> #include<map> #include<set> #include<vector> #include<queue> #include<ctime> using namespace std; typedef long long ll; ll a,p; bool isprime(ll x) { if(x<=1) return false; if(x==2) return true; for(ll i=3;i<=x/i;i++) { if(x % i==0) return false; } return true; } ll mod_pow(ll a,ll p,ll INF) { if(p==0) return 1; ll tmp=mod_pow(a*a%INF,p/2,INF); if(p & 1) tmp=(tmp*a)%INF; return tmp; } int main() { scanf("%I64d%I64d",&p,&a); while(p!=0 || a!=0) { if(isprime(p)) printf("no\n"); else if(mod_pow(a,p,p)==a) printf("yes\n"); else printf("no\n"); scanf("%I64d%I64d",&p,&a); } return 0; }
Private
[
?
]
Run code
Submit