QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#688537#249. Miller Rabin 算法1372037149RE 0ms0kbC++231.3kb2024-10-30 10:40:282024-10-30 10:40:30

Judging History

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

  • [2024-10-30 10:40:30]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-30 10:40:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> du;
#define INF 1e16
#define pi acos(-1)
#define mod 100003
#define base 13331
const int N = 100005;
const int MAXN=200005;
const int siz=270;
const int maxnode = 1e6+5;
const int up = 30;
ll n,s[50005],last[100005];
ll qk(ll a, ll b, ll p) {
    ll ans = 1 % p;
    for (a %= p; b; b >>= 1) {
        if (b & 1) ans = ans * a % p;
        a = a * a % p;
    }
    return ans;
}
ll mul(ll a, ll b, ll p) {
    return (ll)(__int128(a) * b % p);
}
bool Rabin_Miller(ll a, ll n) {
    if (n == 2 || a >= n) return 1;
    if (n == 1 || !(n & 1)) return 0;
    ll d = n - 1;
    while (!(d & 1)) d >>= 1;
    ll t = qk(a, d, n);
    while (d != n - 1 && t != 1 && t != n - 1) {
        t = mul(t, t, n);
        d <<= 1;
    }
    return t == n - 1 || d & 1;
}
bool isprime(ll n) {
    static vector<ll> t = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
    if (n <= 1) return false;
    for (ll k : t) if (!Rabin_Miller(k, n)) return false;
    return true;
}
int main(){
    ios::sync_with_stdio(0);
    ll x;
    while(scanf("%lld,&x")!=EOF){
        if(isprime(x))
            cout<<"Y\n";
        else
            cout<<"N\n";
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

996581938833575363
971646509461160317
773155992127361153
161603952726515268
540879144500456953
476831214764178553
784255927154201144
671096087619405061
805545190025269709
339546334309245137
337726347922962343
222956293307015293
809183111090275843
799050063298926344
691718101820598109
646220213113313...

output:


result: