分解质因数一道题求解
SOS 这些题我昨天刚解决import math
def is_prime(number):
if number > 1:
if number == 2:
return True
if number % 2 == 0:
return False
for each in range(3,int(math.sqrt(number) + 1),2):
if number % each == 0:
return False
return True
return False
def get_primes(number):
while True:
if is_prime(number):
yield number
number += 1
def solve(count):
clist =
for next_prime in get_primes(3):
if next_prime < count:
clist.append(next_prime)
else:
return clist
break
def mincommul(num,nlist):
for i in nlist:
if not num % i:
return
def main():
try:
count = int(input('count = '))
clist1 = solve(count)
clist2 = []
while True:
clist2.append(mincommul(count,clist1))
count = mincommul(count,clist1)
if count == 1:
break
print(clist2)
except Exception as error:
print('An error has occurred:' + str(error))
if __name__ == '__main__':
main()
关键是要看懂我的代码 wuqramy 发表于 2020-4-12 17:20
关键是要看懂我的代码
{:10_282:}看不懂讲解下大佬 def f(n: int, /) -> list:
res=[]
while not n&1:
n>>=1
res.append(2)
temp=3
maximum=int(n**0.5)
while temp<=maximum:
if not n%temp:
while not n%temp:
n//=temp
res.append(temp)
maximum=int(n**0.5)
temp+=2
if n!=1:
res.append(n)
return res
print(f(int(input())))我能说一句吗,你好菜啊
不光菜,更是连思考都不思考,上来就问。
这样能学好吗? 永恒的蓝色梦想 发表于 2020-4-12 17:41
我能说一句吗,你好菜啊
不光菜,更是连思考都不思考,上来就问。
这样能学好吗?
{:10_250:}我错了 我已经写过了然后才问你们看看有别的方法吗!!1 永恒的蓝色梦想 发表于 2020-4-12 17:41
我能说一句吗,你好菜啊
不光菜,更是连思考都不思考,上来就问。
这样能学好吗?
可能他没学过分解质因数
(满满的不服)
页:
[1]