Skip to content

Commit

Permalink
k진수에서 소수 개수 구하기 문제 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeVicTech committed Feb 11, 2023
1 parent dd4b06c commit 77fb75e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions 미분류/k진수에서_소수_개수_구하기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# https://school.programmers.co.kr/learn/courses/30/lessons/92335

#https://github.com/encrypted-def/kakao-blind-recruitment/blob/master/2022-blind/Q2.py
# 좀더 깔끔한 풀이

# 소수 판별하는 방법

def is_prime(n):
if n <= 1:
return False
i = 2
while i <= n**0.5:
if n%i == 0:
return False
i+=1
return True

def solution(n, k):
arr = []
for i in range(1000000):
if k**i > 1000000:
break
arr.append(k**i)

arr.reverse()

result = []

for x in arr:
if n >= x:
result.append(str(n//x))
n -= (n//x * x)
else:
result.append('0')

result = ''.join(result)
result = result.split('0')

cnt = 0

for item in result:
if item == '':
continue
elif is_prime(int(item)):
cnt += 1

return cnt

0 comments on commit 77fb75e

Please sign in to comment.