QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#32009 | #249. Miller Rabin 算法 | gsh# | WA | 100ms | 3612kb | C++23 | 722b | 2022-05-14 19:53:08 | 2022-05-14 19:53:11 |
Judging History
answer
#include<algorithm>
#include<iostream>
#include<random>
#include<vector>
#include<cstdio>
using namespace std;
#define ll long long
#define For(i,l,r) for(int i=l;i<=r;i++)
#define FOR(i,l,r) for(int i=l;i>=r;i--)
const ll p[11]={0,2,3,5,7,11,13,17,19,23,29};
ll pow(ll a,ll b,ll P){int ans=1;while(b)(b&1)&&(ans=(__int128_t)ans*a%P),a=(__int128_t)a*a%P,b>>=1;return ans%P;}
bool check(ll x)
{
For(i,1,10)if(x==p[i])return 1;if(x<p[10])return 0;
For(i,1,10)
{
ll a=pow(p[i],x-1,x);if(a!=1)return 0;int y=x-1;while(y%2==0)y>>=1;
a=pow(p[i],y,x);while(a!=1){ll b=(__int128_t)a*a%x;if(b==1&&a!=x-1)return 0;a=b;}
}
return 1;
}
int main(){ll x;while(cin>>x)cout<<(check(x)?"Y\n":"N\n");return 0;}
详细
Test #1:
score: 0
Wrong Answer
time: 100ms
memory: 3612kb
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'