結果
問題 | No.3030 ミラー・ラビン素数判定法のテスト |
ユーザー | Tlapesium |
提出日時 | 2020-08-15 19:32:34 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,810 bytes |
コンパイル時間 | 3,151 ms |
コンパイル使用メモリ | 214,324 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-18 18:09:16 |
合計ジャッジ時間 | 4,231 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
コンパイルメッセージ
main.cpp: In function 'bool isprime_int32(int)': main.cpp:29:27: warning: 'd' may be used uninitialized [-Wmaybe-uninitialized] 29 | if (modpow(a[i], d, N) == 1)continue; | ~~~~~~^~~~~~~~~~~~ main.cpp:17:20: note: 'd' was declared here 17 | int s = 0, d; | ^ In lambda function, inlined from 'bool isprime_int64(ll)' at main.cpp:55:13: main.cpp:48:54: warning: 'd' may be used uninitialized [-Wmaybe-uninitialized] 48 | for (x %= mod; k; x = x * x % mod, k >>= 1) | ~~^~~~~ main.cpp: In function 'bool isprime_int64(ll)': main.cpp:43:19: note: 'd' was declared here 43 | ll s = 0, d; | ^
ソースコード
#pragma GCC optimize("O3") //#pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx2") #define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10) #include <bits/stdc++.h> constexpr int INF = 2147483647; constexpr long long int INF_LL = 9223372036854775807; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; using namespace std; typedef long long int ll; typedef unsigned long long int ull; bool isprime_int32(int N) { if (N == 2)return 1; if (N % 2 == 0 || N <= 2)return 0; int s = 0, d; int a[] = { 2, 13, 23, 1662803 }; for (int i = N - 1; i % 2 == 0; i /= 2)s++, d = i/2; auto modpow = [](ll x, ll k, ll mod) { ll res = 1; for (x %= mod; k; x = x * x % mod, k >>= 1) if (k & 1) res = res * x % mod; return res; }; for (int i = 0; i < 4; i++) { bool flag = 1; if (N <= a[i])continue; if (modpow(a[i], d, N) == 1)continue; for (int j = 0; j < s; j++) if (modpow(a[i], d * (1 << j), N) == N - 1) { flag = 0; break; } if (flag)return 0; } return 1; } bool isprime_int64(ll N) { if (N == 2)return 1; if (N % 2 == 0 || N <= 2)return 0; ll s = 0, d; ll a[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,37 }; for (int i = N - 1; i % 2 == 0; i /= 2)s++, d = i / 2; auto modpow = [](ll x, ll k, ll mod) { ll res = 1; for (x %= mod; k; x = x * x % mod, k >>= 1) if (k & 1) res = res * x % mod; return res; }; for (int i = 0; i < 12; i++) { bool flag = 1; if (N <= a[i])continue; if (modpow(a[i], d, N) == 1)continue; for (int j = 0; j < s; j++) if (modpow(a[i], d * (1 << j), N) == N - 1) { flag = 0; break; } if (flag)return 0; } return 1; } int main() { io_init; int N; cin >> N; for (int i = 0; i < N; i++) { int x; cin >> x; cout << x << " " << isprime_int64(x) << endl; } }