发帖格式不好看,下面我沙发再发一次,谢谢指导 import java.util.Scanner; import java.math.BigInteger; import java.util.LinkedList; import java.util.Queue; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); System.out.println(solve(n)); in.close(); } public static BigInteger solve(int n) { BigInteger m1 = BigInteger.valueOf(0); BigInteger m = BigInteger.valueOf(0); BigInteger yes = BigInteger.valueOf(1); Queue<BigInteger> queue = new LinkedList<BigInteger>(); if (n <= 3) { return BigInteger.valueOf(1); } while (queue.size() < 3) { queue.offer(m1); } while (n - 3 > 0) { --n; yes = yes.add(queue.poll()); queue.offer(yes); } while (!queue.isEmpty()) { m = m.add(queue.poll()); } return m.add(yes); } }