Skip to content

Commit 77fb75e

Browse files
committed
k진수에서 소수 개수 구하기 문제 추가
1 parent dd4b06c commit 77fb75e

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# https://school.programmers.co.kr/learn/courses/30/lessons/92335
2+
3+
#https://github.com/encrypted-def/kakao-blind-recruitment/blob/master/2022-blind/Q2.py
4+
# 좀더 깔끔한 풀이
5+
6+
# 소수 판별하는 방법
7+
8+
def is_prime(n):
9+
if n <= 1:
10+
return False
11+
i = 2
12+
while i <= n**0.5:
13+
if n%i == 0:
14+
return False
15+
i+=1
16+
return True
17+
18+
def solution(n, k):
19+
arr = []
20+
for i in range(1000000):
21+
if k**i > 1000000:
22+
break
23+
arr.append(k**i)
24+
25+
arr.reverse()
26+
27+
result = []
28+
29+
for x in arr:
30+
if n >= x:
31+
result.append(str(n//x))
32+
n -= (n//x * x)
33+
else:
34+
result.append('0')
35+
36+
result = ''.join(result)
37+
result = result.split('0')
38+
39+
cnt = 0
40+
41+
for item in result:
42+
if item == '':
43+
continue
44+
elif is_prime(int(item)):
45+
cnt += 1
46+
47+
return cnt

0 commit comments

Comments
 (0)