Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

英文不好,一开始没读懂题,后来发现就是a的p次方模p为a&&p为非素数为yes,否则为no

Posted by CCUT_king at 2018-03-17 12:21:20 on Problem 3641
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator