結果

問題 No.2751 429-like Number
ユーザー mottchanmottchan
提出日時 2024-05-10 23:02:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,578 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-05-10 23:02:47
合計ジャッジ時間 16,136 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 27 ms
10,752 KB
testcase_02 AC 27 ms
11,008 KB
testcase_03 AC 28 ms
10,880 KB
testcase_04 AC 26 ms
10,752 KB
testcase_05 AC 27 ms
10,880 KB
testcase_06 WA -
testcase_07 AC 366 ms
11,008 KB
testcase_08 AC 140 ms
10,752 KB
testcase_09 AC 1,445 ms
10,752 KB
testcase_10 AC 2,039 ms
10,880 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1,463 ms
11,008 KB
testcase_15 AC 102 ms
10,880 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 get_prime(n):
    sieve = [True] * (n + 1) 
    i = 2
    while i * i <= n: 
        if sieve[i]:
            for j in range(i * i, n + 1, i):
                sieve[j] = False
        i += 1
    return [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')
        continue
    cnt=0
    c=0
    for i in range(len(l)):
        c+=1
        if n%l[i] == 0:
            n = n//l[i]
            cnt+=1
            break
    for i in range(len(l)-c):
        c+=1
        if n%l[i] == 0:
            n = n//l[i]
            cnt+=1
            break
    if miller_rabin(n):
        cnt+=1

    if cnt==3:
        print('Yes')
    else:
        print('No')
0