QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#93027 | #144. Primitive root / 原根 | DaBenZhongXiaSongKuaiDi# | 0 | 2ms | 3776kb | C++17 | 1014b | 2023-03-31 09:57:45 | 2023-03-31 09:57:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128_t i128;
ll n,ph;
ll FP(ll bs,ll k){
i128 ret = 1, mul = bs;
while(k){
if(k&1ll) ret = ret*mul%n;
mul = mul*mul%n;
k >>= 1;
}
return (ll)ret;
}
bool chk(ll x){
if(!(x%4)) return 0;
if(!(x%2)) x/=2;
for(int al=2;(ll)al*al<=x;al++)if(!(x%al)){
while(!(x%al)) x/=al;
if(x!=1) return 0;
return 1;
}
return 1;
}
bool calc(ll x){
ll ph_ = ph;
for(int al=2;(ll)al*al<=ph_;al++)if(!(ph_%al)){
if(FP(x,ph/al)==1) return 0;
while(!(ph_%al)) ph_ /= al;
}
return 1;
}
int main(){
scanf("%lld",&n);
if(n==2) printf("1\n");
else if(n==4) printf("3\n");
else if(!chk(n)) printf("-1\n");
else{
ph = n; ll cur = n;
for(int al=2;(ll)al*al<=cur;al++)if(!(cur%al)){
ph /= al, ph *= (al-1);
while(!(cur%al)) cur /= al;
}
if(cur!=1) ph /= cur, ph *= (cur-1);
// system("pause");
for(int al=2;;al++)if(calc(al)){printf("%d\n",al); break;}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 1
Accepted
time: 2ms
memory: 3700kb
input:
433
output:
5
result:
ok good solution
Test #2:
score: 0
Accepted
time: 2ms
memory: 3644kb
input:
197
output:
2
result:
ok good solution
Test #3:
score: 0
Accepted
time: 2ms
memory: 3636kb
input:
733
output:
6
result:
ok good solution
Test #4:
score: 0
Accepted
time: 2ms
memory: 3672kb
input:
859
output:
2
result:
ok good solution
Test #5:
score: 0
Accepted
time: 2ms
memory: 3660kb
input:
449
output:
3
result:
ok good solution
Test #6:
score: 0
Accepted
time: 2ms
memory: 3668kb
input:
263
output:
5
result:
ok good solution
Test #7:
score: -1
Wrong Answer
time: 0ms
memory: 3776kb
input:
683
output:
2
result:
wrong answer wrong solution
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #3:
0%
Subtask #7:
score: 0
Skipped
Dependency #4:
0%
Subtask #8:
score: 0
Skipped
Dependency #5:
0%
Subtask #9:
score: 0
Skipped
Dependency #6:
0%
Subtask #10:
score: 0
Skipped
Dependency #9:
0%