Twice Equation
2024-08-30 04:35:58
题目链接: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;
}
}
}
}
}
最新文章
- 【leetcode】Remove Element
- 简单工厂VS工厂方法
- Redis不同数据类型的的数据结构实现
- Mac OS X 上Lua的安装方法
- nginx 报错 upstream timed out (110: Connection timed out)解决方案
- Entity Framework只entity与DbContext的分离
- SSL简介
- eclipse 中 maven3 创建web项目
- Lucene学习总结之二:Lucene的总体架构
- haproxy 关闭ssl 3.0 加密
- 小议common lisp程序开发流程 - Ever 17 - 博客频道 - CSDN.NET
- Sping--AOP--Annotation
- Quartz格式设置说明
- 芝麻HTTP:Python爬虫入门之URLError异常处理
- [POI 2004]SZP
- 某些情况下调用函数为什么要在函数名前加“(void)”
- 爬虫时遇到的&#39; 编码错误gbk &#39; 的解决方案
- webpack-工程化工具
- vue-i18n和ElementUI国际化使用
- Mac安装LNMP环境,升级php7