結果

問題 No.1747 Many Formulae 2
ユーザー 👑 rin204rin204
提出日時 2021-12-13 01:33:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 1,363 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 76,568 KB
最終ジャッジ日時 2023-09-28 20:23:01
合計ジャッジ時間 3,750 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,396 KB
testcase_01 AC 77 ms
71,284 KB
testcase_02 AC 95 ms
76,568 KB
testcase_03 AC 76 ms
71,180 KB
testcase_04 AC 76 ms
71,220 KB
testcase_05 AC 75 ms
71,184 KB
testcase_06 AC 75 ms
70,916 KB
testcase_07 AC 86 ms
76,128 KB
testcase_08 AC 76 ms
71,420 KB
testcase_09 AC 75 ms
71,160 KB
testcase_10 AC 76 ms
71,372 KB
testcase_11 AC 78 ms
71,136 KB
testcase_12 AC 77 ms
71,088 KB
testcase_13 AC 76 ms
71,308 KB
testcase_14 AC 77 ms
71,100 KB
testcase_15 AC 96 ms
76,520 KB
testcase_16 AC 88 ms
76,120 KB
testcase_17 AC 77 ms
70,996 KB
testcase_18 AC 76 ms
71,096 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
ans = 0
for bit in range(1 << l):
    eq = []
    for i, s in enumerate(S):
        eq.append(s)
        if bit >> i & 1:
            eq.append("+")
    if isprime(eval("".join(eq))):
        ans += 1

print(ans)
0