Q:

how to calculate a function in prolog?

We have to find a function in prolog Q(a,b,n) with a < b and with the following way:
Q(a, b, n) = max { k ∈ N | b ^ k  - a ^ k < = n}
here is the my code but it is always giving me a "no"
qs(A,B,N,R,C) :- R>N, R is B^C-A^C.
qs(A,B,N,R,C) :- A<B, C1 is C, R is B^C1-A^C1, C1 is C+1, R=<N, qs(A,B,N,R,C1).
qs(A,B,N,R) :- A<B, C is 0, qs(A,B,N,R,C).

For example if I had Q(2,3,18) the output should be 2.

A:

qs(A, B, N, R) :-
   A < B,
   once((
      length(_,K),
      B^K - A^K > N
   )),
   R is K-1.

