結果

問題 No.1747 Many Formulae 2
ユーザー 👑 rin204rin204
提出日時 2021-12-13 01:32:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 823 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 76,852 KB
最終ジャッジ日時 2023-09-28 20:22:35
合計ジャッジ時間 3,212 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,220 KB
testcase_01 WA -
testcase_02 AC 94 ms
76,744 KB
testcase_03 AC 76 ms
71,348 KB
testcase_04 WA -
testcase_05 AC 77 ms
71,176 KB
testcase_06 AC 77 ms
71,384 KB
testcase_07 WA -
testcase_08 AC 75 ms
71,228 KB
testcase_09 WA -
testcase_10 AC 78 ms
71,284 KB
testcase_11 AC 78 ms
71,568 KB
testcase_12 AC 76 ms
71,188 KB
testcase_13 AC 77 ms
71,344 KB
testcase_14 AC 76 ms
71,288 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 76 ms
71,284 KB
testcase_18 AC 76 ms
71,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def isprime(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    
    A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022]
    s = 0
    d = n - 1
    while d % 2 == 0:
        s += 1
        d >>= 1
    
    for a in A:
        if a % n == 0:
            return True
        x = pow(a, d, n)
        if x != 1:
            for t in range(s):
                if x == n - 1:
                    break
                x = x * x % n
            else:
                return False
    return True
        

S = input()
se = set()
l = len(S) - 1
for bit in range(1 << l):
    eq = []
    for i, s in enumerate(S):
        eq.append(s)
        if bit >> i & 1:
            eq.append("+")
    se.add(eval("".join(eq)))
    
print(sum(isprime(n) for n in se))
0