結果

問題 No.1747 Many Formulae 2
ユーザー ShirotsumeShirotsume
提出日時 2021-11-19 22:32:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 790 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 81,640 KB
最終ジャッジ日時 2023-08-30 09:17:51
合計ジャッジ時間 3,827 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
74,620 KB
testcase_01 AC 114 ms
74,668 KB
testcase_02 AC 136 ms
79,992 KB
testcase_03 AC 111 ms
74,700 KB
testcase_04 AC 133 ms
80,000 KB
testcase_05 AC 110 ms
74,668 KB
testcase_06 AC 110 ms
74,812 KB
testcase_07 AC 153 ms
81,536 KB
testcase_08 AC 112 ms
74,696 KB
testcase_09 AC 111 ms
74,592 KB
testcase_10 AC 110 ms
74,460 KB
testcase_11 AC 112 ms
74,720 KB
testcase_12 AC 116 ms
74,648 KB
testcase_13 AC 111 ms
74,972 KB
testcase_14 AC 111 ms
74,412 KB
testcase_15 AC 154 ms
81,640 KB
testcase_16 AC 147 ms
81,456 KB
testcase_17 AC 111 ms
74,852 KB
testcase_18 AC 111 ms
74,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import random
from collections import defaultdict
def is_prime(n):
    if n==2:
        return True
    if n==1 or n&1==0:
        return False
    d=(n-1)>>1
    while d&1==0:
        d>>=1

    for k in range(100):
        a=random.randint(1,n-1)
        t=d
        y=pow(a, t, n)
        while t!=n-1 and y!=1 and y!=n-1:
            y=(y*y)%n
            t<<=1
        if y!=n-1 and t&1==0:
            return False
    return True
s = list(input())
ans = 0
for i in range(2 ** (len(s) - 1)):
    x = 0
    now = int(s[0])
    for j in range(len(s) - 1):
        if 1 & (i >> j):
            x += now
            now = int(s[j + 1])
        else:
            now = 10 * now + int(s[j + 1])
    x += now
    now = 0
    if is_prime(x):
        ans += 1
print(ans)

0