Twice Equation

题目链接:https://nanti.jisuanke.com/t/A1541

题意:给你一个L,要你求一个不小于L的最小数字n,对于一个整数m,满足2*(m+1)*m=n*(n+1)。

思路:打表找规律:打了一个

3
20
119
696
4059
23660
137903
803760
4684659
27304196

最后找到规律f(n)=6f(n-1)-f(n-2)+2;用Java大数打表求得。

public class Main {
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        int T=cin.nextInt();
        BigInteger[] f=new BigInteger [1500];
        BigInteger two=new BigInteger("2");
        BigInteger six=new BigInteger("6");
        BigInteger L;
        f[1]=new BigInteger("3");f
        [2]=new BigInteger("20");
        for(int i=3;i<=1200;i++) {
            f[i]=f[i-1].multiply(six).subtract(f[i-2]).add(two);
        }
        for(int i=0;i<T;i++) {
            L=cin.nextBigInteger();
            for(int j=1;j<=1200;j++) {
                if(L.compareTo(f[j])<=0) {
                    System.out.println(f[j]);
                    break;
                }
            }
        }
    }
}

 

posted @ 2019-10-10 15:06  Ldler  Views(206)  Comments(0Edit  收藏  举报