传送门 : 51 nod 原根
code:
#include <iostream>
using namespace std;
typedef long long ll;
ll a[35];
int cnt = 0;
ll FastPowMod(ll a, ll b, ll p){
ll ret = 1;
while(b){
if(b & 1) ret = ret * a % p;
a = a * a % p;
b >>= 1;
}
return ret;
}
void getPrime(ll p){
for(ll i = 2; i * i <= p; ++i){
if(p % i == 0){
while(p % i == 0) p /= i;
a[++cnt] = i;
}
}
if(p > 1) a[++cnt] = p;
}
int main(){
ll p;
cin >> p;
getPrime(p - 1);
for(ll i = 2; i < p; ++i){
bool f = 0;
for(int j = 1; j <= cnt; ++j)
if(FastPowMod(i, (p - 1) / a[j], p ) == 1) {
f = 1;
break;
}
if(!f){
cout << i << endl;
break;
}
}
return 0;
}