QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#750005 | #249. Miller Rabin 算法 | pudding164253 | WA | 21ms | 3688kb | C++14 | 981b | 2024-11-15 12:01:44 | 2024-11-15 12:01:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define uLL unsigned long long
template<class T,class POW>
void fastpow(T x,POW n,POW p,T &ans){
for(;n;n>>=1){
if(n&1){ans*=x;ans%=p;}
x*=x;x%=p;
}
}
/*輸入x,n,p,ans 會將ans修改為x^n%p
對整數/矩陣/不要求精度的浮點 皆有效
模板第一個型別是x,ans 第二個是n,p(應該放LL或__int128)*/
int pri[7]={2,325,9375,28178,450775,9780504,1795265022};/*2^64*/
// int p[3]={2,7,61};/*2^32*/
bool check(const uLL x,const uLL p){
uLL d=x-1,ans=1;fastpow(p,d,x,ans);
if(ans!=1)return 1;
for(;!(d&1);){
d>>=1;ans=1;fastpow(p,d,x,ans);
if(ans==x-1)return 0;
else if(ans!=1)return 1;
}
return 0;
}
bool miller_rabin(const uLL x){
if(x==1)return 0;
for(int e:pri){
if(e==x)return 1;
if(check(x,e))return 0;
}
return 1;
}
int main(){for(uLL n;cin>>n;)printf("%c\n","NY"[miller_rabin(n)]);}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 21ms
memory: 3688kb
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'