// you’re reading...

Project Euler Solutions

Project Euler Problem 47 Solution

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Problem Description

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 primes factors. What is the first of these numbers?

Analysis

Simple approach that took only a few minutes to write. Start with the first number that has 4 distinct prime factors. Continue to increment from that number until 4 consecutive numbers have four distinct prime factors.

Solution

Runs < 5 seconds in Python.

from Euler import factor
 
c = 1
n = 2 * 3 * 5 * 7
while c != 4:
  n += 1
  if len(factor(n)) == 4: c += 1
  else: c = 0
print "Answer to PE47 = ", n-3

Comments

More information on the Euler module can be found on the tools page.

Discussion

No comments for “Project Euler Problem 47 Solution”

Post a comment