結果

問題 No.1747 Many Formulae 2
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-11-19 23:03:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 86,820 KB
実行使用メモリ 76,808 KB
最終ジャッジ日時 2023-08-30 10:08:58
合計ジャッジ時間 3,618 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,388 KB
testcase_01 AC 71 ms
71,432 KB
testcase_02 AC 85 ms
76,732 KB
testcase_03 AC 73 ms
71,528 KB
testcase_04 AC 73 ms
71,520 KB
testcase_05 AC 74 ms
71,324 KB
testcase_06 AC 74 ms
71,380 KB
testcase_07 AC 83 ms
76,808 KB
testcase_08 AC 73 ms
71,100 KB
testcase_09 AC 76 ms
71,376 KB
testcase_10 AC 75 ms
71,276 KB
testcase_11 AC 77 ms
71,328 KB
testcase_12 AC 74 ms
71,416 KB
testcase_13 AC 74 ms
71,404 KB
testcase_14 AC 75 ms
71,380 KB
testcase_15 AC 86 ms
76,728 KB
testcase_16 AC 85 ms
76,576 KB
testcase_17 AC 72 ms
71,240 KB
testcase_18 AC 73 ms
71,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_prime(x: int) -> bool:
	if x < 2: return False
	if x == 2 or x == 3 or x == 5: return True
	if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False

	prime_number = 7
	difference = 4

	while prime_number ** 2 <= x:
		if x % prime_number == 0: return False

		prime_number += difference
		difference = 6 - difference

	return True

s = input()
n = len(s)
ans = 0
for b in range(1 << (n - 1)):
	now = s[0]
	cnt = 0
	for i in range(1, n):
		if b >> (i - 1) & 1:
			cnt += int(now)
			now = s[i]
		else:
			now += s[i]
	cnt += int(now)
	if is_prime(cnt):
		ans += 1
print(ans)
0