相关疑难解决方法(0)

Python列表有多大?

在Python中,列表有多大?我需要一个大约12000个元素的列表.我还能运行排序等列表方法吗?

python size list

108
推荐指数
7
解决办法
15万
查看次数

Python寻找主要因素

两部分问题......

1)试图确定600851475143的最大素数因子,发现这个程序似乎在线工作,问题是我很难弄清楚它是如何工作的(我理解程序正在做什么的基础)...另外,如果您能够了解一些您可能知道找到素数的方法(可能没有测试每个数字)以及您的方法是如何工作的.

我在网上找到的主要因素代码

n = 600851475143
i = 2
while i * i < n:
     while n % i == 0:
         n = n / i
     i = i + 1

print (n)

#takes about ~0.01secs
Run Code Online (Sandbox Code Playgroud)

2)为什么代码比这段代码快得多(代码只是测试速度而没有其他真正的用途)

i = 1
while i < 100:
    i += 1
#takes about ~3secs
Run Code Online (Sandbox Code Playgroud)

python primes

46
推荐指数
11
解决办法
17万
查看次数

在python中坚持项目Euler#3

13195的主要因素是5,7,13和29. 600851475143中最大的素数是多少?

好的,所以我正在研究python中的项目euler问题3.我有点困惑.我不知道我在这个程序中得到的答案是否正确.如果somone可以请告诉我我做错了什么会很棒!

#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 …
Run Code Online (Sandbox Code Playgroud)

python math primes

-1
推荐指数
2
解决办法
7895
查看次数

标签 统计

python ×3

primes ×2

list ×1

math ×1

size ×1