题意:给两个数p和a。先判断p是否是素数,如果是返回no,如果不是则再判断a的p次方取模p是否等于a,如果是返回yes,其他返回no。
题解:快速幂。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cstring>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define ull unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
bool is_prime(int n){
for(int i = 3 ; i <= sqrt(n+0.0);i++){
if(n%i==0){
return 0;
}
}
return 1;
}
ll poww(ll a,ll p){
ll ans = 1,mark = a,mod = p;
while(p){
if(p&1!=0){
ans*=mark;
ans%=mod;
}
mark*=mark;
mark%=mod;
p >>= 1;
}
return ans;
}
int main(){
ll a,p;
while(cin>>p>>a&&(a+p)){
if(is_prime(p)){
cout<<"no"<<endl;
}else if(poww(a,p)==a){
cout<<"yes"<<endl;
}else{
cout<<"no"<<endl;
}
}
}