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;
}
}
}
}
}