# 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. # Find the sum of all numbers which are equal to the sum of the factorial of their digits. # Note: as 1! = 1 and 2! = 2 are not sums they are not included. def factorial(x): y=int(x) n=1 fact=1 while n < y: fact=fact*(n+1) n=n+1 return fact sum1 = 0 for j in range(10,100000): str1 = str(j) length = len(str1) sum = 0 for i in range(1,length+1): sum = sum + factorial(str1[i-1]) if sum == j: sum1 = sum1 + sum print sum1

# Category: Project Euler

# Solution Project Euler – Problem 16: Power digit sum

#Power digit sum # 215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. # What is the sum of the digits of the number 21000? num = 2**1000 str1 = len(str(num)) str2=str(num) sum = 0 for i in range(1,str1+1): sum = sum + int(str2[i-1]) print sum

# Solution Problem Euler – Problem 48:Self powers

# Self powers # The series, 11 + 22 + 33 + ... + 1010 = 10405071317. # Find the last ten digits of the series, 11 + 22 + 33 + ... + 10001000. sum = 0 for i in range(1,1001): sum = sum + i**i num = str(sum) for j in range(len(num)-10,len(num)): print num[j],

# Solution Project Euler – Problem 6:Sum square difference

# Sum square difference # 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 the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640. # Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum. x = raw_input('Enter your choice for n natural number?: ') y = int(x) squaresum = (y*(y+1)*(2*y+1))/6 sum = (y*(y+1)/2)*(y*(y+1)/2) print sum - squaresum

# Solution Project Euler – Problem 21: Amicable Numbers

# Sum of amicable number def divisor_sum(x): # x=raw_input('Enter the number?: ') y=int(x) sum=0 for i in range(1,y): if(y%i == 0): sum+=i return sum import time sum1=0 start = time.time() for t in range(1,10000): call = divisor_sum(t) call1= divisor_sum(call) if call1 == t: sum1 = sum1+int(call1) elapsed = time.time() - start print("%s found in %s seconds") % (sum1,elapsed)

# Solution Project Euler – Problem 20: Factorial digit sum

# Factorial digit sum # Problem 20 # n! means n (n 1) ... 3 2 1 # For example, 10! = 10 9 ... 3 2 1 = 3628800, # and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27. # Find the sum of the digits in the number 100! x= raw_input('Enter the number whose factorial you wanna calculate?: ') y=int(x) n=1 fact=1 while n < y: fact=fact*(n+1) n=n+1 # print fact sum=0 len = len(str(fact)) strg = str(fact) for i in range(1,len+1): # print int(strg[i-1]) sum=sum+int(strg[i-1]) print sum

# Solution Project Euler – Problem 7: 10001st prime

def isPrime(y): i=2 while i < y: if y%i == 0 : return 0 exit() i=i+1 return 1 x= raw_input('Enter the position 1st,2nd,..nth prime number you are looking for?: ') z=int(x) # for l in range(2,z) count = 1 n = 2 while count <= z: if isPrime(n) == 1: if count == z: print n count +=1 n=n+1