QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#462463 | #249. Miller Rabin 算法 | lmeowdn | WA | 8ms | 3860kb | C++14 | 1.7kb | 2024-07-03 19:54:44 | 2024-07-03 19:54:44 |
Judging History
answer
//Shirasu Azusa 2024.7
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
int pr[7]={2,325,9375,28178,450775,9780504,1795265022};
int ksm(int x,int y,int p,int r=1) {
x%=p; for(;y;y>>=1,x=x*x%p) if(y&1) r=r*x%p; return r;
}
bool chk(int x,int n) {
if(x%n==0) return 1; int g=ksm(x,n-1,n); if(g!=1) return 0;
for(int y=n-1;y>1&&y%2==0;) {
y=y/2; int g=ksm(x,y,n);
if(g==n-1) break; else if(g!=1) return 0;
} return 1;
}
char work(int n) {
if(n==2) return 'Y'; else if(n==1||n%2==0||n%5==0) return 'N';
for(int x:pr) if(!chk(x,n)) return 'N'; return 'Y';
}
signed main() {
int x; while(scanf("%lld",&x)!=EOF) putchar(work(x)),putchar('\n');
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 3860kb
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'