program main implicit none integer*8::x,y,z,a,b,c,d,e,f,ab,cd integer*8::i read *,x,y,z a = x*y b = y-x c = y*z d = z-y ! ab = gcd(a,b) ! cd = gcd(c,d) ! a = a/ab ! b = b/ab ! c = c/cd ! d = d/cd call lcm_fraction(a,b,c,d,e,f) print '(i0,"/",i0)',e,f contains recursive function gcd(a,b) result(c) integer*8::a,b,c if(b.eq.0) then c = a else c = gcd(b,MOD(a,b)) end if end function gcd function lcm(a,b) result(c) integer*8,intent(in)::a,b integer*8::c c = (a/gcd(a,b))*b end function lcm subroutine lcm_fraction(a,b,c,d,e,f) ! e/f=lcm(a/b,c/d) ! ! l = a/b*X = c/d*Y = lcm(a/b,c/d) ! b*d*l = a*d*X = c*b*Y = lcm(a*d, b*c) ! l = lcm(a*d, b*c)/(b*d) integer*8::a,b,c,d,e,f integer*8::adbc,bd,gcd_adbcbd adbc = lcm(a*d,b*c) bd = b*d gcd_adbcbd = gcd(adbc, bd) e = adbc/gcd_adbcbd f = bd/gcd_adbcbd end subroutine lcm_fraction end program main