概述
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;
}
}
}
}
}
最后
以上就是活泼高跟鞋为你收集整理的南宁区域赛-- Twice Equation--递推+大数的全部内容,希望文章能够帮你解决南宁区域赛-- Twice Equation--递推+大数所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复