题解 | #循环汉诺塔#
循环汉诺塔
https://www.nowcoder.com/practice/cdf0808f841748faba058c8ef538c731
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.readLine()); long AToB = 1; long AToC = 2; for (int i = 2; i <= n; i++) { long preAToB = AToB; long preAToC = AToC + AToC; AToB = (preAToC + 1) % 1000000007; AToC = (preAToC + preAToB + 2) % 1000000007; } System.out.println(AToB + " " + AToC); } }