結果
問題 |
No.2751 429-like Number
|
ユーザー |
|
提出日時 | 2024-05-10 23:25:27 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,339 bytes |
コンパイル時間 | 200 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 21,760 KB |
最終ジャッジ日時 | 2024-12-20 07:44:42 |
合計ジャッジ時間 | 79,957 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 WA * 2 |
other | AC * 3 WA * 5 TLE * 14 |
ソースコード
def suspect(a, t, n): x = pow(a, t, n) n1 = n - 1 while t != n1 and x != 1 and x != n1: x = pow(x, 2, n) t <<= 1 return t & 1 or x == n1 # メイン # 2^64までの決定的アルゴリズムとして実装しているので、ランダム要素は無い # ランダムとして用いる場合は、check_listにランダム抽出された数を採用し、20~50個程度試す def miller_rabin(n): if n == 2: return True if n < 2 or n % 2 == 0: return False d = (n - 1) >> 1 while d & 1 == 0: d >>= 1 check_list = (2, 7, 61) if n < 2 ** 32 else (2, 325, 9375, 28178, 450775, 9780504, 1795265022) for i in check_list: if i >= n: break if not suspect(i, d, n): return False return True def prime_factorize(n): a = [] cnt=0 while n % 2 == 0 and cnt<2: a.append(2) n //= 2 cnt+=1 f = 3 while f * f <= n and cnt<2: if n % f == 0: a.append(f) n //= f cnt+=1 else: f += 2 return a q = int(input()) for _ in range(q): n = int(input()) l = prime_factorize(n) # print(l,len(l)) if len(l)==2: if miller_rabin(n//(l[0]*l[-1])): print('Yes') else: print('No')