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;
}
}
}
}
}
Twice Equation的更多相关文章
- CodeForces460B. Little Dima and Equation
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- HDU 5937 Equation
题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...
- coursera机器学习笔记-多元线性回归,normal equation
#对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...
- CF460B Little Dima and Equation (水题?
Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...
- Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)
,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...
- ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分
Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- [ACM_数学] Counting Solutions to an Integral Equation (x+2y+2z=n 组合种类)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E 题目大意:Given, n, count the numbe ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- SGU 106 The equation
H - The equation Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Subm ...
随机推荐
- 块设备驱动——ramblock
一. 什么是块设备. 1.1. 一种具有一定结构的随机存取设备,对这种设备的读写是按块进行的,他使用缓冲区来存放暂时的数据,待条件成熟后,从缓存一次性写入设备或者从设备一次性读到缓冲区.可以随机访问, ...
- 【WPS/Visio】WPS word无法复制或编辑Visio对象
前言 Win10,WPS2019,Visio2016. 好像是有一次设置 .vsdx 的默认打开方式为Visio,之后每次在WPS里复制Visio对象,或双击编辑WPS word中以前的Visio对象 ...
- js中箭头函数 及 针对箭头函数this指向问题引出的单体模式
ES6允许使用“箭头”(=>)定义函数 var f = a = > a //等同于 var f = function(a){ return a; } 如果箭头函数不需要参数或需要多个参数, ...
- 深入理解 JavaScript中的变量、值、传参
1. demo 如果你对下面的代码没有任何疑问就能自信的回答出输出的内容,那么本篇文章就不值得你浪费时间了. var var1 = 1 var var2 = true var var3 = [1,2, ...
- Delphi主消息循环研究(Application.Run和Application.Initialize执行后的情况)
Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; 第一步,貌似什么都不做,但如果提前定义I ...
- LeetCode 235. 二叉搜索树的最近公共祖先
235. 二叉搜索树的最近公共祖先 题目描述 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义为:"对于有根树 T 的两个结点 p.q,最近公共祖先 ...
- ASP.NET的面包屑导航控件、树形导航控件、菜单控件
原文:http://blog.csdn.net/pan_junbiao/article/details/8579293 ASP.NET的面包屑导航控件.树形导航控件.菜单控件. 1. 面包屑导航控件— ...
- java中的数据类型,基本数据类型及其包装类型
java中的8大基本类型及其包装类型 1,int--->Integer 2,byte--->Byte 3,short--->Short 4,long--->Long 5,cha ...
- SSM框架的常用注解整理
一.mybatis 1 配置一对多查询和多对多查询的注解方式映射关系: @Results:声明映射关系的配置 Value属性接收 @Result的数组 @Result:配置映射关系 id属性(b ...
- 解决HTML乱码
转自:https://blog.csdn.net/yuxisanno139/article/details/80675426