QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#340528#144. Primitive root / 原根LYT0122#0 1ms3940kbC++141.9kb2024-02-29 09:46:172024-02-29 09:46:19

Judging History

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

  • [2024-02-29 09:46:19]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3940kb
  • [2024-02-29 09:46:17]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
const int N=1e6+9,INF=1e9;
const double eps=1e-5;
typedef pair <int,int> PII;
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
    while(c>='0' && c<='9') {x=x*10+c-48,c=getchar();}
    return x*f;
}
inline ll readll()
{
    ll x=0,f=1;char c=getchar();
    while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
    while(c>='0' && c<='9') {x=x*10+c-48,c=getchar();}
    return x*f;
}
int cnt,p[N],tot;
ll mod;
ll quick_pow(ll x,ll y,ll mod)
{
    ll ans=1;
    while(y!=0)
    {
        if(y&1) ans=ans*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return ans;
}
int main()
{
    #ifdef FILEIO
        freopen("in.in","r",stdin);
        freopen("out.out","w",stdout);
    #endif
    mod=readll();
    if(mod==2 || mod==4)
    {
        puts("1");
        return 0;
    }
    // ll x=mod,phi=mod;
    // for(int i=2;i<=x/i;i++)
    // {
    //     if(x%i==0)
    //     {
    //         phi=phi/i*(i-1);
    //         while(x%i==0) x/=i;
    //         if(i&1) cnt++;
    //     }
    // }
    // if(x>1) phi=phi/x*(x-1),cnt+=(x&1);
    // if(cnt!=1)
    // {
    //     puts("-1");
    //     return 0;
    // }
    ll x=mod-1,phi=mod-1;
    for(int i=2;i<=x/i;i++)
    {
        if(x%i==0)
        {
            p[++tot]=i;
            while(x%i==0) x/=i;
        }
    }
    for(int i=1;i<=phi;i++)
    {
        while(quick_pow(i,phi,mod)!=1) i++;
        bool flag=true;
        for(int j=1;j<=tot && flag;j++)
            if(quick_pow(i,phi/p[j],mod)==1) flag=false;
        if(flag)
        {
            cout<<i;
            break;
        }
    }
    cerr<<endl<<1e3*clock()/CLOCKS_PER_SEC<<"ms";
    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: 0ms
memory: 3912kb

input:

433

output:

5

result:

ok good solution

Test #2:

score: 0
Accepted
time: 0ms
memory: 3908kb

input:

197

output:

2

result:

ok good solution

Test #3:

score: 0
Accepted
time: 0ms
memory: 3728kb

input:

733

output:

6

result:

ok good solution

Test #4:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

859

output:

2

result:

ok good solution

Test #5:

score: 0
Accepted
time: 0ms
memory: 3940kb

input:

449

output:

3

result:

ok good solution

Test #6:

score: 0
Accepted
time: 1ms
memory: 3916kb

input:

263

output:

5

result:

ok good solution

Test #7:

score: -1
Wrong Answer
time: 0ms
memory: 3940kb

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%