-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.py
64 lines (46 loc) · 1.11 KB
/
2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def solution(n, k):
answer = 0
temp = str(n) if k == 10 else n_numeric(n, k)
n_to_list = num_to_list(temp)
# if is_prime(int(temp)):
# answer += 1
for num in n_to_list:
print(num)
if num != '0' and is_prime(int(num)):
answer+=1
return answer
def num_to_list(s):
temp = []
str_temp = ""
if int(s) == 0 :
return temp
for i, x in enumerate(s):
if x != '0':
str_temp += x
else:
if str_temp:
temp.append(str_temp)
str_temp = ""
temp.append('0')
if i == len(s)-1:
if str_temp:
temp.append(str_temp)
return temp
def is_prime(a: int):
if a == 1 or a == 0:
return False
for i in range(2, int(a ** 0.5) + 1):
if a % i == 0:
return False
return True
def n_numeric(a, n_th):
temp = ""
while True:
temp += str(a % n_th)
a = a // n_th
if not a:
break
return temp[::-1]
# print(solution(437674, 3))
print(solution(120,10))
# print(solution())