結果
問題 | No.2751 429-like Number |
ユーザー |
|
提出日時 | 2024-05-10 22:35:11 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,507 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-12-20 06:28:59 |
合計ジャッジ時間 | 16,000 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 7 WA * 15 |
ソースコード
def suspect(a, t, n):x = pow(a, t, n)n1 = n - 1while t != n1 and x != 1 and x != n1:x = pow(x, 2, n)t <<= 1return t & 1 or x == n1# メイン# 2^64までの決定的アルゴリズムとして実装しているので、ランダム要素は無い# ランダムとして用いる場合は、check_listにランダム抽出された数を採用し、20~50個程度試すdef miller_rabin(n):if n == 2:return Trueif n < 2 or n % 2 == 0:return Falsed = (n - 1) >> 1while d & 1 == 0:d >>= 1check_list = (2, 7, 61) if n < 2 ** 32 else (2, 325, 9375, 28178, 450775, 9780504, 1795265022)for i in check_list:if i >= n:breakif not suspect(i, d, n):return Falsereturn Truedef get_prime(n):sieve = [True] * (n + 1)i = 2while i * i <= n:if sieve[i]:for j in range(i * i, n + 1, i):sieve[j] = Falsei += 1return [i for i in range(2, n + 1) if sieve[i]]l = get_prime(4000)# print(l)q = int(input())for _ in range(q):n = int(input())if n==1:print('No')continuecnt=0for i in l:if n%i == 0:n = n//icnt+=1breakfor i in l:if n%i == 0:n = n//icnt+=1breakif miller_rabin(n):cnt+=1if cnt==3:print('Yes')else:print('No')