gpt4 book ai didi

java - java中的费马方程

转载 作者:太空宇宙 更新时间:2023-11-04 07:47:29 25 4
gpt4 key购买 nike

我正在尝试用费马的最后一个方程制作一个递归分析程序,但它不断返回方程错误我不明白?

public class fermatdata 
{
public static void data(int a, int b, int c, int n)
{
if ((Math.pow(a, n)) + (Math.pow(b, n)) == (Math.pow(c, n)))
{
System.out.println("Holy smokes, Fermat was wrong!");
return;
}
else
{
data(a-1, b-1, c-1, n-1);
if (n < 2)
{
return;
}
else
{
data(a-1, b-1, c-1, n-1);
}
}
System.out.println("No, that doesn't work. Fermat was right");
}
public static void main(String[] args)
{
System.out.println("Fermat's last theorem stated that the formula a^n + b^n = c^n while n>2 and all of the numbers are integers will never be correct. Here I am going to do an analysis with all the numbers starting at 100,000 and count backwords to 3");
data(100000, 100000, 100000, 100000);
}
}

最佳答案

尝试删除第一行,如下所示:

        data(a-1, b-1, c-1, n-1);

好的,现在看看 Math.pow(100000,100000) 给出了什么(无穷大)。我认为问题在于您使用的值太高(至少对于 n 而言)。

关于java - java中的费马方程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15055737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com