题目链接: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;
}
}
}
}
}

最新文章

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

热门文章

  1. Spring框架学习总结
  2. SparkStreaming DStream转换
  3. 教你在 IntelliJ IDEA 中使用 VIM!
  4. Linux环境安装mongodb
  5. Jafka源码分析——网络架构
  6. 使用 ref 和 out 传递数组注意事项
  7. java的idea项目文件夹合并,怎么分开
  8. 使用PHPWord生成word文档
  9. vue脚手架通过UI界面创建项目
  10. memset,内存初始化函数