/*
Euler #46 in Picat.
"""
It was proposed by Christian Goldbach that every odd composite number can be
written as the sum of a prime and twice a square.
9 = 7 + 2×1^2
15 = 7 + 2×2^2
21 = 3 + 2×3^2
25 = 7 + 2×3^2
27 = 19 + 2×2^2
33 = 31 + 2×1^2
It turns out that the conjecture was false.
What is the smallest odd composite that cannot be written as the
sum of a prime and twice a square?
"""
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(euler46).
euler46 =>
Res = 0,
GotIt = 0,
foreach(I in 3..2..10000, not prime(I), GotIt == 0)
S = round(sqrt(I/2)),
Found = 0,
foreach(J in 1..S, Found == 0)
Ts = J*J*2,
if prime(abs(I-Ts)) then
Found := 1
end
end,
if Found == 0 then
Res := I,
GotIt := 1
end
end,
println(res=Res).