ICPC Nanning L. Twice Equation (打表找规律)(level 1)

题目链接

题意:

2*m(m+1) = n*(n+1)

然后给你一个L,让你输出一个最小的n>=L,(所有数都是整数)

解析:

这道题虽然只有level 1,比赛的时候也很多人做出来,但是这种题我是完全做不出来....

m: 0  tot: 0  n:0.0
m: 2  tot: 12  n:3.0
m: 14  tot: 420  n:20.0
m: 84  tot: 14280  n:119.0
m: 492  tot: 485112  n:696.0
m: 2870  tot: 16479540  n:4059.0
m: 16730  tot: 559819260  n:23660.0
m: 97512  tot: 19017375312  n:137903.0
m: 568344  tot: 646030941360  n:803760.0
m: 3312554  tot: 21946034630940  n:4684659.0
m: 19306982  tot: 745519146510612  n:27304196.0
m: 112529340  tot: 25325704946729880  n:159140519.0
m: 655869060  tot: 860328449042305320  n:927538920.0

打了这么多项的表也找不出任何规律..我本来以为是用那个数学公式推出来的公式

结果...直接找规律,猜公式....我队友找到的规律是

f[i]=6*f[i-1]-6*f[i-3]+f[i-4]

其实官方的题解的规律是f[i]=6*f[i-1]-f[i-2]+2

这个公式其实可以化成上面那个式子的



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

public class Main {
	
	
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		
		for(int o=0;o<t;o++){
			BigInteger f0=BigInteger.ZERO;
			BigInteger f1=BigInteger.valueOf(3);
			BigInteger f2=BigInteger.valueOf(20);
			BigInteger f3=BigInteger.valueOf(119);
			BigInteger six=BigInteger.valueOf(6);
			BigInteger L=sc.nextBigInteger();
			if(L.compareTo(f1)<=0)
			{
				System.out.println(f1);
				continue;
			}
			if(L.compareTo(f2)<=0)
			{
				System.out.println(f2);
				continue;
			}
			while(L.compareTo(f3)>0){
				BigInteger res=f3.multiply(six).subtract(f1.multiply(six)).add(f0);
				f0=f1;
				f1=f2;
				f2=f3;
				f3=res;
			}
			System.out.println(f3);
		}
	}

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值