把1分解为若干个互不相同的单位分数之和。
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.StringReader; import java.util.*; public class Main { static Scanner sc = new Scanner(System.in); static int n = sc.nextInt(); static long lcm1_20 = 232792560L; //1 - 20的最小公倍数 static int a[]; static void dfs(int step,int now,int result){ if(step == n){ if(result != lcm1_20)return; for(int i = 0;i < n;i++){ System.out.printf("1/" + a[i]+" "); } System.out.println(); return; } if(result > lcm1_20)return; for(int i = now + 1;i <= 20;i++){ a[step] = i; dfs(step + 1,i, (int) (result + (lcm1_20 / i))); } } public static void main(String[] args) throws IOException { a = new int[n]; dfs(0,0,0); } }