/* Number theory problem in 2012 CMO in Picat. http://community.wolfram.com/groups/-/m/t/793922 """ Given two positive integers a and b. The two numbers satisfy the following conditions: a−b is a prime number p and a×b is a perfect square n^2 . Find the smallest value of a no less than 2012. """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. % import sat. import cp. % import math. main => go. % sat: 2.8s % cp: 0.07s go => nolog, Primes = primes(2012), A :: 2012..10000, B :: 2..2012, P :: Primes, N :: 2..2012, A #>= B, P #= A-B, A*B #= N*N, Vars = [P,B,N], solve($[min(A),up,report(printf("A: %d\n", A))],Vars), println(a=A), println(b=B), println(p=P), % println(z=Z), println(n=N), nl. % sat: 1.5s % cp: 0.065s go2 => nolog, Max = 10000, Primes = primes(2012), member(A,2012..Max), % println(testing=A), B :: 2..2012, P :: Primes, N :: 2..2012, A #>= B, P #= A-B, A*B #= N*N, Vars = [P,B,N], solve($[min(A),up,report(printf("A: %d\n", A))],Vars), println(a=A), println(b=B), println(p=P), println(n=N), nl.