QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#722514#249. Miller Rabin 算法AutomatiC__Compile Error//C++231.3kb2024-11-07 19:20:402024-11-07 19:20:40

Judging History

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

  • [2024-11-07 19:20:40]
  • 评测
  • [2024-11-07 19:20:40]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cctype>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cstdlib>
#include <bitset>
#include <deque>
#include <random>
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll binpow(ll a, ll b, ll mod) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}
bool miller_rabin(ll n) {
    if (n < 3 || n % 2 == 0) return n == 2;
    if (n % 3 == 0) return n == 3;
    ll u = n - 1, t = 0;
    while (u % 2 == 0) u /= 2, ++t;
    for (int i = 1; i <= 9; i++) {
        ll a = myrand() % (n - 3) + 2;
        ll v = binpow(a, u, n);
        if (v == 1) continue;
        int s = 0;
        for (s = 0; s < t; s++) {
            if (v == n - 1) break;
            v = v * v % n;
        }
        if (s == t) return false;
    }
    return true;
}
int main() {
    mt19937_64 myrand(time(0));
    ll x;
    while (cin >> x) {
        if (miller_rabin(x)) {
            cout << "Y" << endl;
        } else {
            cout << "N" << endl;
        }
    }
    return 0;
}

Details

answer.code: In function ‘bool miller_rabin(ll)’:
answer.code:38:16: error: ‘myrand’ was not declared in this scope; did you mean ‘srand’?
   38 |         ll a = myrand() % (n - 3) + 2;
      |                ^~~~~~
      |                srand