QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#480867#249. Miller Rabin 算法Kalenist#WA 14ms3792kbC++20810b2024-07-16 19:19:302024-07-16 19:19:30

Judging History

This is the latest submission verdict.

  • [2024-07-16 19:19:30]
  • Judged
  • Verdict: WA
  • Time: 14ms
  • Memory: 3792kb
  • [2024-07-16 19:19:30]
  • Submitted

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define ull unsigned long long
using namespace std;
int n,a[13]={0,2,3,5,7,11,13,17,19,23,29,31,37};
ull x;
mt19937 rnd(20061130);
inline int get(int l,int r){return rnd()%(r-l+1)+l;}
inline ull mul(ull a,ull b,ull mod)
{
    ull res=a*b-(ull)((long double)a/mod*b+1e-9)*mod;
    return res<0?res+mod:res;
}

inline ull fpow(int a,ull b,ull mod)
{
    ull res=1;a%=mod;
    for(;b;b>>=1,a=mul(a,a,mod))
        if(b&1) res=mul(res,a,mod);
    return res;
}

inline bool chk(long long x)
{
    if(x == 1) return false;
    For(i,1,12) if(fpow(a[i],x,x) != a[i]%x) 
        return false;
    return true;
}

int main()
{
    while(scanf("%lld",&x) != EOF)
        puts(chk(x)?"Y":"N");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 14ms
memory: 3792kb

input:

996581938833575363
971646509461160317
773155992127361153
161603952726515268
540879144500456953
476831214764178553
784255927154201144
671096087619405061
805545190025269709
339546334309245137
337726347922962343
222956293307015293
809183111090275843
799050063298926344
691718101820598109
646220213113313...

output:

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
...

result:

wrong answer 2nd lines differ - expected: 'Y', found: 'N'