严肃讨论。参照埃及分数百度百科的最后面的Pascal代码
将真分数分解为埃及分数
https://www.nowcoder.com/practice/e0480b2c6aa24bfba0935ffcca3ccb7b
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()) { String[] str = in.nextLine().split("\\/"); long a = Integer.valueOf(str[0]); long b = Integer.valueOf(str[1]); long c = 0; String res = ""; for ( ; a != 1 && b % a != 0 ;) { c = b / a + 1; a = a * c - b; b = b * c; res += ("1/" + c + "+"); } if (b % a == 0 && a != 1) { res += ("1/" + b / a); } else if (a == 1) { res += ("1/" + b); } System.out.println(res); } } }