문제
링크텍스트
풀이
결과
def f_t(id_t):
if id_t == 0:
n, r = "17", 3
if id_t == 1:
n, r = "011", 2
return n, r
def solution(numbers):
prime_cache = {}
def is_prime(x):
if x in prime_cache:
return prime_cache[x]
if x < 2:
prime_cache[x] = False
return False
for k in range(2, int((x+1)**0.5) + 1):
if x % k == 0:
prime_cache[x] = False
return False
prime_cache[x] = True
return True
def f_s(id_n, i, ns_i):
id_n[i] = True
ns_i += numbers[i]
n_i = int(ns_i)
is_prime(n_i)
for j in range(len(numbers)):
if id_n.get(j) is None:
f_s(id_n.copy(), j, ns_i)
for i in range(len(numbers)):
id_n = {}
if numbers[i] != "0":
f_s(id_n, i, "")
return sum([i == True for i in prime_cache.values()])
for i in range(2):
print(f'test case {i}')
n, r = f_t(i)
a = solution(n)
print(a)
print(r)