欧拉项目python代码

第12题:

拥有超过500个因数的第一个三角数(1+2+3+4+......)

def findivisionnum(num):
    count = 0
    n=1
    import math
    while count<num:
        count = 0
        for i in range(1,int(math.sqrt(triangle(n)))+1):
            if not triangle(n)%i:
                count +=2
        if int(math.sqrt(triangle(n)))==math.sqrt(triangle(n)):
                count -=1
        n += 1
    return triangle(n-1)

def triangle(n):
  return n*(n+1)/2

print findivisionnum(500)

[Finished in 13.9s]
时间: 2024-09-30 16:54:34

欧拉项目python代码的相关文章

欧拉项目005:最小公倍数

Smallest multiple Problem 5 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? 就是找出1....20 所有数的最

欧拉项目004:寻找最大的回文数

Problem 4: Largest palindrome product A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. 寻找有两

006:欧拉项目平方和与和的平方的差

Sum square difference Problem 6 The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of

欧拉项目007:第10001个素数

10001st prime Problem 7 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? 使用埃拉托斯特尼筛法,不懂得自行Wiki 我的python代码: # -*- coding:utf-8 -*- #使用埃拉托斯尼特晒法 #从2开始 import math def

欧拉函数及代码实现

对正整数n,欧拉函数是小于n的正整数中与n互质的数的数目,它又称为Euler’s totient function.φ函数.欧拉商数等. 例如φ(8)=4,因为1,3,5,7均和8互质,特殊的(φ(1)=1). 1.根据欧拉函数公式:euler(x) = x*(1-1/p1)(1-1/p2)……(1-1/pn),p为x的质因数.用公式法求解代码 int euler(int n){ int res=n,a=n; for(int i=2;i*i<=a;i++){ if(a%i==0){ res=re

欧拉计划(python) problem 31

Coin sums Problem 31 In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation: 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p). It is possible to make £2 in the following way: 1×£1 + 1×50p + 2×

欧拉项目010:2000000以内的素数和

Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. 还是使用Sieve of Eratosthenes 算法 我的python代码例如以下: #coding:utf-8 #从2到sqrt(n) # 不用全部的都用遍历.从i**2,步长为i,i*2,i*3肯定都不是质素. # 从i*

欧拉项目代码(1--7)

第七题 求第10001个质数(用这个代码,我的笔记本大概算了40s): count=1 num=3 def findPrime(s): i=2 a=s while i<s/2: if s%i == 0: s=s/i break else: i=i+1 if s==a: return True else: return False while count <10001: if findPrime(num): count =count + 1 num = num +2 else: num = nu

欧拉计划(python) problem 1

problem 1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. python code: k3=0; k5=0; result=0; for i in range(1,10