南宁区域赛-- Twice Equation--递推+大数

For given LL, find the smallest nn no smaller than LL for which there exists an positive integer mmfor which 2m(m + 1) = n(n + 1)2m(m+1)=n(n+1).

Input

This problem contains multiple test cases. The first line of a multiple input is an integer T (1 \le T < 1000)T(1≤T<1000) followed by TT input lines. Each line contains an integer L (1 \le L < 10^{190})L(1≤L<10190).

Output

For each given LL, output the smallest nn. If available nn does not exist, output -1−1.

样例输入复制

3
1
4
21

样例输出复制

3
20
119

一定要推理出前几项规律!!!!!!,注意打表规律!!!!



import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin=new Scanner(System.in);
		BigInteger n;
		int t;
		t=cin.nextInt();
		for(int i=0;i<t;i++)
		{
			n=cin.nextBigInteger();
			BigInteger th=new BigInteger("3");
			BigInteger a=new BigInteger("20");
			if(n.compareTo(th)<=0)
			{
				System.out.println("3");
			}else if(n.compareTo(a)<=0)
			{
				System.out.println("20");
			}else
			{
				BigInteger c;
				BigInteger b=new BigInteger("20");
				a=new BigInteger("20");
				b=th;
				th=new BigInteger("2");
				while(true)
				{
					c=a.multiply(new BigInteger("6")).subtract(b).add(th);
					if(c.compareTo(n)>=0)
					{
						System.out.println(c);
						break;
					}
					b=a;
					a=c;
				}
			}
		}
	}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值