結果
| 問題 | 
                            No.8030 ミラー・ラビン素数判定法のテスト
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-01-02 08:33:02 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,022 bytes | 
| コンパイル時間 | 1,593 ms | 
| コンパイル使用メモリ | 168,076 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-11-18 19:12:21 | 
| 合計ジャッジ時間 | 2,426 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 7 WA * 3 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using Int8 = int8_t;
using Int16 = int16_t;
using Int32 = int32_t;
using Int64 = int64_t;
using Int128 = __int128_t;
using Word8 = uint8_t;
using Word16 = uint16_t;
using Word32 = uint32_t;
using Word64 = uint64_t;
using Word128 = __uint128_t;
using Int = int_fast64_t;
using Word = uint_fast64_t;
using F32 = float;
using F64 = double;
using F80 = long double;
using VS = vector<string>;
using VVS = vector<vector<string>>;
using VB = vector<bool>;
using VVB = vector<vector<bool>>;
using VI = vector<Int>;
using VW = vector<Word>;
using VVI = vector<vector<Int>>;
using VVW = vector<vector<Word>>;
using PII = pair<Int,Int>;
using PWW = pair<Word,Word>;
using VPII = vector<pair<Int,Int>>;
using VPWW = vector<pair<Word,Word>>;
#define LOOP(n) for(Int _ipiewnsjiw=0; _ipiewnsjiw<(n); _ipiewnsjiw++)
#define REP(i,n) for(Int i=0, i##_len=(n); i<i##_len; ++i)
#define RANGE(i,a,b) for(Int i=(a), i##_len(b); i<=i##_len; ++i)
#define SZ(obj) ((Int)(obj).size())
#define UNIQUE(obj) (obj).erase(unique((obj).begin(),(obj).end()),(obj).end())
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
Int mult(Int a, Int b, Int md) {
  Int ret = a * b - md * (Int) (1.L / md * a * b);
  return ret + md * (ret < 0) - md * (ret >= (Int)md);
}
Int power(Int a, Int b, Int md) {
  a %= md;
	Int ans = 1;
  while (b > 0) {
    if (b & 1) ans = mult(ans, a, md);
    a = mult(a, a, md);
    b >>= 1;
  }
	return ans;
}
bool miller_rabin(Int n) {
  if (n < 2 || n % 6 % 4 != 1) return (n | 1) == 3;
  Int s = __builtin_ctzll(n - 1);
  Int d = n >> s;
  Int A[7] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
  for (Int a : A) {
    Int p = power(a % n, d, n), i = s;
    while (p != 1 && p != n - 1 && a % n && i--) p = mult(p, p, n);
    if (p != n - 1 && i != s) return false;
  }
  return true;
}
int main() {
  int Q; cin >> Q;
  while (Q--) {
    Word64 x; cin >> x;
    cout << x << ' ' << miller_rabin(x) << '\n';
  }
  return 0;
}