plus(X,0,X).
plus(0,Y,0).
plus(s(X),Y,s(Z)):- plus(X,Y,Z).
multi(0,Y,0).
multi(s(0),Y,Y).
multi(s(X),Y,Z):- multi(X,Y,T), plus(Y,T,Z).
p(s(0),0).
p(s(s(X)),s(Y)):- p(s(X),Y).
fac(s(X),Y):- p(s(X),T1),fac(T1,T2),multi(T2,s(X),Y).