n^2+(n+1)^2 为完全平方数问题的解法与实现

 

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+"毫秒");
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值