File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments