12 2013 档案
摘要:Summation of primesProblem 10The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two million.The code resemble :import mathlimit = 2000000crosslimit = int(math.sqrt(limit))#sieve = [False] * limitsieve = [False for i in range(0, limit)]for i in range(4, limit +
阅读全文
摘要:Special Pythagorean tripletProblem 9A Pythagorean triplet is a set of three natural numbers,abc, for which,a2+b2=c2For example, 32+ 42= 9 + 16 = 25 = 52.There exists exactly one Pythagorean triplet for whicha+b+c= 1000.Find the productabc.The code is simple:a = 0b = 0c = 0totalSum = 1000cMax = int(t
阅读全文
摘要:Largest product in a seriesProblem 8Find the greatest product of five consecutive digits in the 1000-digit number.731671765313306249192251196744265747423553491949349698352031277450632623957831801698480186947885184385861560789112949495459501737958331952853208805511125406987471585238630507156932909632
阅读全文
摘要:10001st primeProblem 7By 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?The solve this one, we should learn how to check whether a number is prime, can also refer to Problem 3The whole code is as follows: 1 import ma
阅读全文
摘要:Sum square differenceProblem 6The sum of the squares of the first ten natural numbers is,12+ 22+ ... + 102= 385The square of the sum of the first ten natural numbers is,(1 + 2 + ... + 10)2= 552= 3025Hence the difference between the sum of the squares of the first ten natural numbers and the square o
阅读全文
摘要:Smallest multipleProblem 52520 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 isevenly divisibleby all of the numbers from 1 to 20?From problem 3, we get a list of prime factors of a number . Base on this
阅读全文
摘要:Largest palindrome productProblem 4A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 9199.Find the largest palindrome made from the product of two 3-digit numbers.The python code is as follows:def isPalindromic(data): list...
阅读全文
摘要:Largest prime factorProblem 3The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ?The answer:import mathdef getLargestPrime(data): list = [] i = 2 while i <= math.sqrt(data): #while i <= data/2: if data%i == 0 : lis...
阅读全文
摘要:Even Fibonacci numbersProblem 2Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...By considering the terms in the Fibonacci sequence whose values do not exceed four million,
阅读全文
摘要:Multiples of 3 and 5Problem 1If 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.the direct way the answer :def isMutiple(target, divider1, divider2): if (target % d...
阅读全文