QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#32009#249. Miller Rabin 算法gsh#WA 100ms3612kbC++23722b2022-05-14 19:53:082022-05-14 19:53:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-14 19:53:11]
  • 评测
  • 测评结果:WA
  • 用时:100ms
  • 内存:3612kb
  • [2022-05-14 19:53:08]
  • 提交

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'