分数的运算
import java.io.*; import java.util.*; public class Main { static int gcd(int x,int y){ if(y == 0) return x; return gcd(y,x%y); } static int lcm(int x,int y){ return x * y / gcd(x,y); } static String hj(int x1x2,int mo){ if(x1x2 ==0 || mo == 0){ return 0 + " " + 0; } int g = gcd(x1x2,mo); return "" + (x1x2/g) + " " + (mo/g); } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); int x1 = sc.nextInt(); int y1 = sc.nextInt(); int x2 = sc.nextInt(); int y2 = sc.nextInt(); int mo = lcm(y1,y2); int x11 = mo/y1*x1;int x22 = mo/y2*x2; if(x11+x22 < 0) { System.out.println("-" + hj(x11 + x22, -mo)); }else { System.out.println(hj(x11 + x22, mo)); } if(x11-x22 < 0) { System.out.println("-" + hj(x11 - x22, -mo)); }else { System.out.println(hj(x11 - x22, mo)); } if(x1*x2 < 0) { System.out.println( hj(x1 * x2, y1 * y2)); }else { System.out.println(hj(x1 * x2, y1 * y2)); } if(x1*y2 < 0) { System.out.println("-" + hj(x1* y2, -(x2 * y1))); }else { System.out.println(hj(x1* y2, x2 * y1)); } } }