QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#480863 | #249. Miller Rabin 算法 | Kalenist# | WA | 0ms | 3720kb | C++20 | 845b | 2024-07-16 19:18:35 | 2024-07-16 19:18:35 |
Judging History
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,15) if(fpow(a[i],x,x) != a[i]%x)
return false;
return true;
}
int main()
{
freopen("test.in","r",stdin);
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: 0ms
memory: 3720kb
input:
996581938833575363 971646509461160317 773155992127361153 161603952726515268 540879144500456953 476831214764178553 784255927154201144 671096087619405061 805545190025269709 339546334309245137 337726347922962343 222956293307015293 809183111090275843 799050063298926344 691718101820598109 646220213113313...
output:
result:
wrong answer 1st lines differ - expected: 'N', found: ''