The first two consecutive numbers to have two distinct prime factors are:
14 = 2
7
15 = 3
5

15 = 3

The first three consecutive numbers to have three distinct prime factors are:
644 = 2²
7
23
645 = 3
5
43
646 = 2
17
19.


645 = 3


646 = 2


Find the first four consecutive integers to have four distinct primes factors. What is the first of these numbers?
Performance improvements:
Suppose we have to check number 80 for prime divisibility. The first prime can only be 2 because the next prime 3 will yield to a greater number (3 * 3 * 3 * 3 > 80).
Stop prime division when maximum prime number is reached yield to 20 x faster code execution. The maximum prime depends on primes already found.
number = x * x * x * x ( x = maximum prime number )
number = 2 * x * x * x
number = 2 * 3 * x * x
number = 2 * 3 * 5 * x
Problem47 = 134043 elapsed time: 117 ms. Test Passed.
Geen opmerkingen:
Een reactie posten