結果

問題 No.1747 Many Formulae 2
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2021-11-21 02:33:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 1,301 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 7,956 KB
最終ジャッジ日時 2023-09-03 17:49:33
合計ジャッジ時間 2,075 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,736 KB
testcase_01 AC 16 ms
7,792 KB
testcase_02 AC 20 ms
7,860 KB
testcase_03 AC 15 ms
7,812 KB
testcase_04 AC 16 ms
7,800 KB
testcase_05 AC 16 ms
7,824 KB
testcase_06 AC 15 ms
7,916 KB
testcase_07 AC 18 ms
7,916 KB
testcase_08 AC 16 ms
7,840 KB
testcase_09 AC 16 ms
7,800 KB
testcase_10 AC 16 ms
7,792 KB
testcase_11 AC 17 ms
7,792 KB
testcase_12 AC 16 ms
7,780 KB
testcase_13 AC 15 ms
7,768 KB
testcase_14 AC 16 ms
7,732 KB
testcase_15 AC 22 ms
7,880 KB
testcase_16 AC 19 ms
7,772 KB
testcase_17 AC 16 ms
7,956 KB
testcase_18 AC 16 ms
7,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
N = len(S)
ans = 0
for i in range(2**(N-1)):
    cnd = []
    for j in range(N-1):
        if (i>>j)&1:
            cnd.append(j)
    if len(cnd) == 0:
        tmp = int(S)
    else:
        tmp = int(S[:cnd[0]+1])
        n = len(cnd)
        now = cnd[0]+1
        for i in range(1,n):
            tmp += int(S[now:cnd[i]+1])
            now = cnd[i]+1
        tmp += int(S[cnd[-1]+1:])
    if len(prime_factorize(tmp)) == 1:
        ans += 1
print(ans)
    
0