結果

問題 No.1747 Many Formulae 2
ユーザー titiatitia
提出日時 2021-11-19 21:37:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 1,115 ms
コンパイル使用メモリ 86,836 KB
実行使用メモリ 89,024 KB
最終ジャッジ日時 2023-08-30 07:42:21
合計ジャッジ時間 4,822 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
88,476 KB
testcase_01 AC 114 ms
88,708 KB
testcase_02 AC 116 ms
88,888 KB
testcase_03 AC 102 ms
88,600 KB
testcase_04 AC 142 ms
88,664 KB
testcase_05 AC 100 ms
88,336 KB
testcase_06 AC 102 ms
88,560 KB
testcase_07 AC 180 ms
88,832 KB
testcase_08 AC 105 ms
88,632 KB
testcase_09 AC 107 ms
88,592 KB
testcase_10 AC 105 ms
88,140 KB
testcase_11 AC 107 ms
88,300 KB
testcase_12 AC 113 ms
88,636 KB
testcase_13 AC 109 ms
88,384 KB
testcase_14 AC 103 ms
88,440 KB
testcase_15 AC 261 ms
89,024 KB
testcase_16 AC 192 ms
88,932 KB
testcase_17 AC 104 ms
88,340 KB
testcase_18 AC 99 ms
88,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

S=input().strip()

def calc(S):
    #print("!",S)
    if len(S)==0:
        yield 0
    for i in range(1,len(S)+1):
        x=int(S[:i])
        #print("?",x,S[i:],list(calc(S[i:])))
        for j in calc(S[i:]):
            yield x+j

import math
x=10**6
L=math.floor(math.sqrt(x)) # 平方根を求める

Primelist=[i for i in range(x+1)]
Primelist[1]=0 # 1は素数でないので0にする.
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]


ANS=0
for j in calc(S):
    if j==1:
        continue
    for k in Primes:
        if j!=k and j%k==0:
            break
    else:
        ANS+=1

print(ANS)
0