import cp. % % Reversible: find Degree and N given M % go2 => Ms = [4,20,105], % The multifactorials to identify foreach(M in Ms) println(m=M), Degree :: 1..10, % limit of the degree N :: 1..100, % limit of N All = findall([N,Degree,M], (multifactorial_reversible(N,Degree,M), solve([M,N,Degree]))), foreach([NN,DD,MM] in All.sort) printf("n=%d degree=%d m=%d\n",NN,DD,MM) end, nl end, nl. % reversible variant (using CP) multifactorial_reversible(N,_D,M) :- N #<= 0, M #= 1. multifactorial_reversible(N,D,M) :- D #> 0, N #> 0, ND #= N-D, multifactorial_reversible(ND,D,M1), M #= N*M1.