mod(X, Y, Mod) :- 
    Mod is X - (Y * (X // Y)).

gcd(A, B, Gcd) :- 
    0 =:= B, !, Gcd = A.
gcd(A, B, Gcd) :- 
    mod(A, B, Mod), gcd(B, Mod, Gcd).

prime_from_(A, F, Prime_from_) :- 
    call((A =< F, !; mod(A, F, Mod), 0 =\= Mod, Sum is 1 + F, 
    prime_from_(A, Sum, Prime_from__1), tru = Prime_from__1)), 
    !, 
    Prime_from_ = tru.
prime_from_(A, F, Prime_from_) :- 
    Prime_from_ = fals.

primep(A, Prime_) :- 
    prime_from_(A, 2, Prime_).

num_primes_(A, N, Num_primes_) :- 
    N =< 1, !, Num_primes_ = A.
num_primes_(A, N, Num_primes_) :- 
    (primep(N, Primep), tru = Primep -> Cond = 1; Cond = 0), 
    Sum is A + Cond, Diff is N - 1, 
    num_primes_(Sum, Diff, Num_primes_).

num_primes(N, Num_primes) :- 
    num_primes_(0, N, Num_primes).

list_primes_dot(A, N, List_primes_dot) :- 
    N =< 1, !, List_primes_dot = A.
list_primes_dot(A, N, List_primes_dot) :- 
    (primep(N, Primep), tru = Primep -> Cond = [N| A]; Cond = A), 
    Diff is N - 1, 
    list_primes_dot(Cond, Diff, List_primes_dot).

% list_primes(+N, -List_primes):
% Előállítja a prímek listáját n-ig.
list_primes(N, List_primes) :- 
    list_primes_dot([], N, List_primes).

