Project Euler 47-Distinct primes factors

Distinct primes factors

Problem 47

The first two consecutive numbers to have two distinct prime factors are:

14 = 2 × 7
15 = 3 × 5

The first three consecutive numbers to have three distinct prime factors are:

644 = 2² × 7 × 23
645 = 3 × 5 × 43
646 = 2 × 17 × 19.

Find the first four consecutive integers to have four distinct prime factors. What is the first of these numbers?

 

Answer:
134043
Completed on Sat, 6 Apr 2013, 05:40

Go to the thread for problem 47 in the forum.

 

n=1000000
a=[0 for i in range(n+1)]
i=2
while i< =n: if (a[i]==0): j=2*i while j

Project Euler 48-Self powers

Self powers

Problem 48

The series, 11 + 22 + 33 + ... + 1010 = 10405071317.

Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000.

 

Answer:
9110846700
Completed on Fri, 5 Apr 2013, 12:33

Go to the thread for problem 48 in the forum.

 

ans=0
i=1
F=10**10
for i in range(1,1001):
p=1
for j in range(i): p=p*i%F
ans=(ans+p)%F
print i
print ans

Project Euler 3-Largest prime factor

Largest prime factor

Problem 3

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

 

Answer:
6857
Completed on Fri, 5 Apr 2013, 12:14

Go to the thread for problem 3 in the forum.

 

import math
n=600851475143
i=2
print math.sqrt(n)
while i< =math.sqrt(n): if (n%i==0): while (n%i==0): n=n/i print i; i=i+1 print n

Project Euler 2-Even Fibonacci numbers

Even Fibonacci numbers

Problem 2

Each 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, find the sum of the even-valued terms.

Answer:
4613732
Completed on Fri, 5 Apr 2013, 06:37

Go to the thread for problem 2 in the forum.

 Even(是偶数的意思……(─.─|||

f=[1,1,1]
i=2
ans=0
while f[i]+f[i-1]<4000000:
i=i+1
f.append(f[i-1]+f[i-2])
if (f[i]%2==0): ans=ans+f[i]
print sum(f)-1,f,ans