-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonTip-71.py
More file actions
55 lines (45 loc) · 978 Bytes
/
Copy pathPythonTip-71.py
File metadata and controls
55 lines (45 loc) · 978 Bytes
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
from math import *
def isprime(n):
if n == 1:
return False
for i in range(2, int(sqrt(n)+1)):
if n % i == 0:
return False
return True
def t(n):
L = []
while isprime(n) == False:
for i in range(2, n):
if isprime(i):
if n % i == 0:
L.append(i)
n = n // i
break
L.append(n)
return L
def h(n):
L = [i for i in range(2, n+1)]
L1 = []
for i in L:
if isprime(i):
continue
else:
L1.append(i)
for i in L1:
L.remove(i)
L2 = [t(i) for i in L1]
L1 = []
for i in L2:
for j in i:
L1.append(j)
L1 += L
L2 = []
for i in L:
x = L1.count(i)
if x != 1:
s = str(i) + '^' + str(x)
else:
s = str(i)
L2.append(s)
return str(n) + '=' + '*'.join(L2)
print(h(6))