domains
num,result=integer
predicates
lcm(num,num)
lcm(num,num,result)
gcd(num,num)
gcd(num,num,result)
input()
clauses
input():-
readint(X1),
readint(X2),i
write("gcd="),gcd(X1,X2,Y),write(Y).
lcm(X1,X2):-
lcm(X1,X2,Y),write(Y),nl.
lcm(X1,X2,Y):-
gcd(X1,X2,Y1),Y=X1*X2/Y1.
gcd(X1,X2):-
gcd(X1,X2,Y),write(Y),nl.
gcd(X1,0,Y):-
Y=X1.
gcd(X1,X2,Y):-
X1=X2,Y=X2.
gcd(X1,X2,Y):-
X1<X2,gcd(X2,X1,Y).
gcd(X1,X2,Y):-
X3=X1 mod X2, gcd(X2,X3,Y).
goal
input().
No comments:
Post a Comment