문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/92335
def is_prime(value): if value <= 1: return False
for i in range(2, int(value**0.5)+1): if value % i == 0: return False return True
def solution(n, k): answer = 0 str_value = '' stack = []
while n > 0: stack.append(n % k) n = n//k
while len(stack) > 0: str_value += str(stack.pop())
sub_strs = str_value.split('0')
for i in sub_strs: if i == '': continue
if is_prime(int(i)): answer += 1
return answer
|