odd在python_卡在python项目Euler#3上

13195的素数是5、7、13和29。600851475143的最大素数是多少?

好的,所以我正在研究python中的项目Euler问题3。我有点困惑。我无法确定我通过该程序获得的答案是否正确。如果有人能告诉我即时消息做错了,那太好了!

#import pdb

odd_list=[]

prime_list=[2] #Begin with zero so that we can pop later without errors.

#Define a function that finds all the odd numbers in the range of a number

def oddNumbers(x):

x+=1 #add one to the number because range does not include it

for i in range(x):

if i%2!=0: #If it cannot be evenly divided by two it is eliminated

odd_list.append(i) #Add it too the list

return odd_list

def findPrimes(number_to_test, list_of_odd_numbers_in_tested_number): # Pass in the prime number to test

for i in list_of_odd_numbers_in_tested_number:

if number_to_test % i==0:

prime_list.append(i)

number_to_test=number_to_test / i

#prime_list.append(i)

#prime_list.pop(-2) #remove the old number so that we only have the biggest

if prime_list==[1]:

print "This has no prime factors other than 1"

else:

print prime_list

return prime_list

#pdb.set_trace()

number_to_test=raw_input("What number would you like to find the greatest prime of?\n:")

#Convert the input to an integer

number_to_test=int(number_to_test)

#Pass the number to the oddnumbers function

odds=oddNumbers(number_to_test)

#Pass the return of the oddnumbers function to the findPrimes function

findPrimes(number_to_test , odds)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值