import java.util.Scanner; /** * 先将 a/b 转换成 1/x+y/z 的形式 * y/z 使用递归继续分解,直到分子为1 * * b除以a,得商x,得余数y b=a*x+y * a/b = 1/(x+1) + (a-y)/b(x+1) */ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String[] str = sc.next().split("/"); // 分子 int a = Integer.parseInt(str[0]); // 分母 int b = Integer.parseInt(str[1]); result = new StringBuffer(); process(a, b, result); System.out.println(result); } } private static void process(int a, int b, StringBuffer result) { if (result.length() != 0) { result.append("+"); } int x = b / a; if (a == 1 || b % a == 0) { result.append("1/").append(x); } else { int y = b % a; result.append("1/").append(x + 1); process(a - y, b * (x + 1), result); } } static StringBuffer result; }