递归的思想

Vissan 发表于 1年前 · 关联问题 一鸣师姐种田

`import java.util.Scanner;

public class Main {

public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); while (n-- > 0) { System.out.println(zhongdi(in.nextInt(), in.nextInt())); } in.close(); } public static int zhongdi(int m, int n) { if (m == n) return 4 *m; else { if (m > n) return zhongdi(n, n) + zhongdi(m - n, n); else return zhongdi(m, m) + zhongdi(n - m, m); } }

}// end of Main `