| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
英文不好,一开始没读懂题,后来发现就是a的p次方模p为a&&p为非素数为yes,否则为no#include <iostream>
/*快速幂取模*/
using namespace std;
typedef long long ll;
ll f(ll x,ll y)
{
ll base=x,r=1,mo=y;
while(y)
{
if(y&1)
r=(r*base)%mo;
base=(base*base)%mo;
y>>=1;
}
return r;
}
bool is_pri(ll x)
{
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
return false;
}
return true;
}
int main()
{
ll p,a;
while(cin >> p >> a,p||a)
{
if(f(a,p)==a&&!is_pri(p))
cout << "yes" << endl;
else
cout << "no" << endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator