QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#374827 | #3051. Identity Function | SolitaryDream# | WA | 1ms | 3584kb | C++17 | 1006b | 2024-04-02 18:41:01 | 2024-04-02 18:41:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+1e3+7;
int phi(int x)
{
int ans=x;
for(int i=2;i*i<=x;i++)
if(x%i==0)
{
ans=ans/i*(i-1);
while(x%i==0)
x/=i;
}
if(x!=1)
ans=ans/x*(x-1);
return ans;
}
int qpow(int a,int b,int P)
{
int ret=1;
while(b)
{
if(b&1)
ret=ret*a%P;
b>>=1;
a=a*a%P;
}
return ret;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
int w=phi(phi(n));
int pn=phi(n);
vector<int> ans;
for(int i=1;i*i<=w;i++)
if(w%i==0)
{
if(qpow(n,i,pn)==1)
ans.push_back(i);
if(qpow(n,w/i,pn)==1)
ans.push_back(w/i);
}
if(ans.size())
cout<<*min_element(ans.begin(),ans.end())<<"\n";
else
cout<<"-1\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3584kb
input:
3
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
4
output:
-1
result:
ok single line: '-1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3488kb
input:
15
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
2
output:
-1
result:
wrong answer 1st lines differ - expected: '1', found: '-1'