Skip to main content

Posts

Showing posts from April, 2016

Problem 27 Project Euler Solution with python

Quadratic primes Euler discovered the remarkable quadratic formula: n ² + n + 41 It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 40 2 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and certainly when n = 41, 41² + 41 + 41 is clearly divisible by 41. The incredible formula   n ² − 79 n + 1601 was discovered, which produces 80 primes for the consecutive values n = 0 to 79. The product of the coefficients, −79 and 1601, is −126479. Considering quadratics of the form: n ² + an + b , where | a | < 1000 and | b | < 1000 where | n | is the modulus/absolute value of n e.g. |11| = 11 and |−4| = 4 Find the product of the coefficients, a and b , for the quadratic expression that produces the maximum number of primes for consecutive values of n , starting with n = 0. Before I start solving this problem, I would like to apologize for not posting the solution for these many days. I will try to

Problem 26 Project Euler Solution with python

Reciprocal cycles A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given: 1 / 2 =  0.5 1 / 3 =  0.(3) 1 / 4 =  0.25 1 / 5 =  0.2 1 / 6 =  0.1(6) 1 / 7 =  0.(142857) 1 / 8 =  0.125 1 / 9 =  0.(1) 1 / 10 =  0.1 Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can be seen that 1 / 7 has a 6-digit recurring cycle. Find the value of d < 1000 for which 1 / d contains the longest recurring cycle in its decimal fraction part. First of all I am sorry for not posting these many days. Firstly I was not able to concentrate on posting the solution because I had some other important work. Secondly as I was not really paying attention I was not able to find the solution for this problem. I was completely lost in a wrong way to solve this problem. I was thinking that I should use python decimal module to solve this problem but my assumption was wrong and I had to come a

Problem 25 Project Euler Solution With python

1000-digit Fibonacci number The Fibonacci sequence is defined by the recurrence relation: F n = F n −1 + F n −2 , where F 1 = 1 and F 2 = 1. Hence the first 12 terms will be: F 1 = 1 F 2 = 1 F 3 = 2 F 4 = 3 F 5 = 5 F 6 = 8 F 7 = 13 F 8 = 21 F 9 = 34 F 10 = 55 F 11 = 89 F 12 = 144 The 12th term, F 12 , is the first term to contain three digits. What is the index of the first term in the Fibonacci sequence to contain 1000 digits? I know that if you have learned programming(Whatever may be the source) you should have come across this sequence called as Fibonacci sequence named after Fibonacci . Even if you have not come across this sequence at any time in your life, not a problem then to. Fibonacci is a very simple sequence. we start with 0,1, the next number will be 1(0+1), next number will be 2(1+1), next number will be 3(2+1) and so on. Briefly present number in the sequence is the sum of the previous two terms in the sequence. Now to solve

Problem 24 Project Euler Solution with python

Lexicographic permutations A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are: 012   021   102   120   201   210 What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? I don't know how many of you are thinking that this problem will have a very big program. But in the real case this problem has  just 28 lines including the comments. Yes! I am not lying, if you don't believe me then go check the program. As we are using python it has become easy for us to get the solution. But to be frank we can get even faster solution. To get even faster solution I suggest you to have a look at the following: How to find the rank of a word in a dictionary   Method to find rank of a word   Even though the faster sol

Problem 23 Project Euler Solution with python

Non-abundant sums A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. A number n is called deficient if the sum of its proper divisors is less than n and it is called abundant if this sum exceeds n . As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the smallest number that can be written as the sum of two abundant numbers is 24. By mathematical analysis, it can be shown that all integers greater than 28123 can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit. Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers. I personally liked this p