如何找出前N个斐波那契数中符合w³-1形式的数?
No, 0 is the only Fibonacci number that can be written in the form (w^3 -1). Here's why:
Manual Check of Small Fibonacci Numbers
Looking at the first few Fibonacci numbers:
- (0 = 1^3 -1) (valid, (w=1))
- (1): (1+1=2) isn't a perfect cube
- (2): (2+1=3) isn't a perfect cube
- (3): (3+1=4) isn't a perfect cube
- (5): (5+1=6) isn't a perfect cube
- (8): (8+1=9) isn't a perfect cube
- All larger Fibonacci numbers grow exponentially, and their value plus 1 never results in a perfect cube.
Mathematical Proof
Our equation is (Fib(n) = w^3 -1), or rearranged: (w^3 - Fib(n) = 1).
By Mihăilescu's Theorem (previously Catalan's Conjecture), the only pair of positive perfect powers that differ by exactly 1 are (9=3^2) and (8=2^3) (since (3^2 - 2^3 =1)). For our equation to hold, (w^3) would need to be one of these perfect powers, but:
- If (w^3=8), then (Fib(n)=7), which isn't a Fibonacci number.
- If (w^3=9), that's not a perfect cube.
This rules out any possible solutions except when (w=1), which gives (Fib(n)=0). Number theory research confirms there are no larger solutions to (Fib(n)+1 =w^3).
Notes on Your Code
Your current code works correctly for the range of Fibonacci numbers that fit in a long (up to the 90th term). Beyond that, long will overflow, so if you need to check larger values, switch to BigInteger. Here's a modified version:
public static List<BigInteger> generateFibonacciNumbers(int N) { List<BigInteger> fibonacciNumbers = new ArrayList<>(); BigInteger a = BigInteger.ZERO, b = BigInteger.ONE; fibonacciNumbers.add(a); if (N > 1) fibonacciNumbers.add(b); for (int i = 2; i < N; i++) { BigInteger c = a.add(b); fibonacciNumbers.add(c); a = b; b = c; } return fibonacciNumbers; } public static boolean isW3Minus1(BigInteger num) { if (num.compareTo(BigInteger.ZERO) < 0) return false; BigInteger target = num.add(BigInteger.ONE); BigInteger low = BigInteger.ONE; BigInteger high = target; while (low.compareTo(high) <= 0) { BigInteger mid = low.add(high).divide(BigInteger.TWO); BigInteger cube = mid.multiply(mid).multiply(mid); int comparison = cube.compareTo(target); if (comparison == 0) return true; else if (comparison < 0) low = mid.add(BigInteger.ONE); else high = mid.subtract(BigInteger.ONE); } return false; }
内容的提问来源于stack exchange,提问作者mary

