-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
44 lines (37 loc) · 856 Bytes
/
main.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
import math
def isPrime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
for i in range(3, int(math.sqrt(n)) + 1, 2):
if n % i == 0:
return False
return True
def primeFactors(n):
if isPrime(n):
print(n)
return
i = 2
isFirstFactor = True
while i <= n:
number = 0
while n % i == 0:
number += 1
n //= i
if number != 0:
if isFirstFactor:
isFirstFactor = False
else:
print("*", end='')
if number != 1:
print(f"{i}^{number}", end='')
else:
print(f"{i}", end='')
i += 1
if __name__ == "__main__":
n = int(input())
primeFactors(n)