import math
def is_prime(n):#判断是否是质数
if n==1:
return False
if n==2:
return True
else:
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
return False
return True
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
运行
def func(number):
temp = number
prime_list=[]
while temp>0:
if is_prime(temp):
prime_list.append(str(temp))
break
for i in range(2,int(math.sqrt(temp))+1):
if temp%i==0 and is_prime(i):
prime_list.append(str(i))
temp = temp//i
break
return "*".join(prime_list)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
运行
>>> print("%d=%s"%(90,func(90)))
90=2*3*3*5
- 1
- 2
- 1
- 1
- 1