mod(I,J,M) :- I<J, M=I.
mod(I,J,M) :- K is I - J, mod(K,J,M).