QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#374827#3051. Identity FunctionSolitaryDream#WA 1ms3584kbC++171006b2024-04-02 18:41:012024-04-02 18:41:01

Judging History

你现在查看的是最新测评结果

  • [2024-04-02 18:41:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3584kb
  • [2024-04-02 18:41:01]
  • 提交

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";
}

详细

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'