/*
Euler #47 in Picat.
"""
The first two consecutive numbers to have two distinct prime factors are:
14 = 2 x 7
15 = 3 x 5
The first three consecutive numbers to have three distinct
prime factors are:
644 = 2^2 x 7 x 23
645 = 3 x 5 x 43
646 = 2 x 17 x 19.
Find the first four consecutive integers to have four distinct primes
factors. What is the first of these numbers?
"""
This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com
See also my Picat page: http://www.hakank.org/picat/
*/
main => go.
go => time(euler47).
euler47 =>
garbage_collect(100_000_000),
MaxN = 1000000,
% F = [0 : I in 1..MaxN],
% It's much faster using an array.
F = new_array(MaxN),
% foreach(I in 1..MaxN) F[I] := 0 end,
bind_vars(F,0), % faster
foreach(I in 2..MaxN-1)
if F[I] == 0 then
foreach(J in 2*I..I..MaxN-1)
F[J] := F[J] + 1
end
end
end,
Goal = [4,4,4,4],
% println(goal=Goal),
Found = 0,
foreach(I in 2..MaxN-3, Found==0)
if [F[J] : J in I..I+3] == Goal then
println(I),
Found := 1
end
end.