期限 2026-05-25 17:00
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

35 lines
840 B

import sys
def findFactors(num):
exponent = 0
print(f"{num} =", end="")
while num % 2 == 0:
exponent += 1
num //= 2
if exponent > 1:
print(f" 2^{exponent} *", end="")
elif exponent == 1:
print(" 2 *", end="")
for i in range(3, int(num**0.5) + 1, 2):
exponent = 0
while num % i == 0:
exponent += 1
num //= i
if exponent > 1:
print(f" {i}^{exponent} *", end="")
elif exponent == 1:
print(f" {i} *", end="")
if num != 1:
print(f" {num} *", end="")
print("\b ")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python prime.py <Integer>")
sys.exit(1)
num = int(sys.argv[1])
if num <= 1:
print(f"{num}")
else:
findFactors(num)