n^2+(n+1)^2 为完全平方数问题的解法与实现
数学证明
3 4 5
20 21 29
119 120 169
696 697 985
4059 4060 5741
23660 23661 33461
137903 137904 195025
803760 803761 1136689
4684659 4684660 6625109
27304196 27304197 38613965
159140519 159140520 225058681
927538920 927538921 1311738121
涉及大数运算
import java.io.*;
import java.sql.*;
import java.math.BigInteger;
import java.math.*;
public class jie1
{
public static void main(String[] args)
{
int c=400;
int i=0;
long t=System.currentTimeMillis();
BigInteger a = new BigInteger("0");
BigInteger b = new BigInteger("1");
BigInteger d = new BigInteger("1");
BigInteger ten =new BigInteger("10");
while(d.compareTo(ten.pow(c))<0){i++;
BigInteger temp =d.add(a.add(b)).multiply(new BigInteger("2"));
BigInteger tempa = temp.subtract( b);
BigInteger tempb = temp.subtract( a);
BigInteger tempc = temp.add( d);
a = tempa;
b = tempb;
d = tempc;
System.out.println(i+":"+a.toString()+" "+b.toString()+" "+d.toString());
}
i=(int)(System.currentTimeMillis()-t);
System.out.println("用时"+i+"毫秒");
}
}
import java.sql.*;
import java.math.BigInteger;
import java.math.*;
public class jie1
{
public static void main(String[] args)
{
int c=400;
int i=0;
long t=System.currentTimeMillis();
BigInteger a = new BigInteger("0");
BigInteger b = new BigInteger("1");
BigInteger d = new BigInteger("1");
BigInteger ten =new BigInteger("10");
while(d.compareTo(ten.pow(c))<0){i++;
BigInteger temp =d.add(a.add(b)).multiply(new BigInteger("2"));
BigInteger tempa = temp.subtract( b);
BigInteger tempb = temp.subtract( a);
BigInteger tempc = temp.add( d);
a = tempa;
b = tempb;
d = tempc;
System.out.println(i+":"+a.toString()+" "+b.toString()+" "+d.toString());
}
i=(int)(System.currentTimeMillis()-t);
System.out.println("用时"+i+"毫秒");
}
}