ICPC Asia Nanning 2017 L. Twice Equation (规律 高精度运算)
题目链接:Twice Equation
Description
For given \(L\), find the smallest \(n\) no smaller than \(L\) for which there exists an positive integer \(m\) for which \(2m(m + 1) = n(n + 1)\).
Input
This problem contains multiple test cases. The first line of a multiple input is an integer \(T (1 \le T < 1000)\) followed by \(T\) input lines. Each line contains an integer \(L (1 \le L < 10^{190})\).
Output
For each given \(L\), output the smallest \(n\). If available nn does not exist, output \(−1\).
Sample Input
3
1
4
21
Sample Output
3
20
119
Solution
题意
给出一个整数 \(L\),求大于等于 \(L\) 的最小整数 \(n\) 满足存在一个整数 \(m\) 使得 \(2m(m + 1) = n(n + 1)\)。
题解
打表找规律
\]
然后用 Java 大数求解即可。
Code
import java.util.Scanner;
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
BigInteger[] a = new BigInteger[1000];
// 打表
a[0] = BigInteger.ZERO;
a[1] = BigInteger.valueOf(3);
BigInteger six = new BigInteger("6");
BigInteger two = new BigInteger("2");
for(int i = 2; i < 300; ++i) {
a[i] = ((a[i - 1].multiply(six)).subtract(a[i - 2])).add(two);
}
int t = in.nextInt();
while (t-->0){
boolean flag = false;
BigInteger l = in.nextBigInteger();
for(int i = 0; i < 1000; ++i) {
if(a[i].compareTo(l) >= 0) {
System.out.println(a[i]);
flag = true;
break;
}
}
if(!flag) System.out.println(-1);
}
}
}
ICPC Asia Nanning 2017 L. Twice Equation (规律 高精度运算)的更多相关文章
- ICPC Asia Nanning 2017 F. The Chosen One (高精度运算)
题目链接:The Chosen One 比赛链接:ICPC Asia Nanning 2017 题意 \(t\) 组样例,每组给出一个整数 \(n(2\le n\le 10^{50})\),求不大于 ...
- ICPC Asia Nanning 2017 I. Rake It In (DFS+贪心 或 对抗搜索+Alpha-Beta剪枝)
题目链接:Rake It In 比赛链接:ICPC Asia Nanning 2017 Description The designers have come up with a new simple ...
- ICPC Asia Nanning 2017 F. The Chosen One (大数、规律、2的k次幂)
Welcome to the 2017 ACM-ICPC Asia Nanning Regional Contest.Here is a breaking news. Now you have a c ...
- 2017 ACM/ICPC Asia 南宁区 L The Heaviest Non-decreasing Subsequence Problem
2017-09-24 20:15:22 writer:pprp 题目链接:https://nanti.jisuanke.com/t/17319 题意:给你一串数,给你一个处理方法,确定出这串数的权值, ...
- The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum
题目:https://nanti.jisuanke.com/t/41422 思路:预处理 #include<bits/stdc++.h> using namespace std; ][]= ...
- 2017 ACM ICPC Asia Regional - Daejeon
2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...
- 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest
2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...
- 2017 ACM/ICPC Asia Regional Qingdao Online
Apple Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submi ...
- 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路
transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 132768/1 ...
随机推荐
- php中的list()
list()在php中上一个语言结构,并不是一个函数.类似array(),不过array()这个东西我们现在一般很少使用了,因为从php5.4版本开始,我们会直接使用[]来定义数组. 那么,list( ...
- 6、基于highcharts实现的线性拟合,计算部分在java中实现,画的是正态概率图
1.坐标点类 package cn.test.domain; public class Point { double x; double y; public Point(){ } public Poi ...
- 仿flask写的web框架
某大佬仿flask写的web框架 web_frame.py from werkzeug.local import LocalStack, LocalProxy def get_request_cont ...
- 运维01 VMware与Centos系统安装
VMware与Centos系统安装 今日任务 1.Linux发行版的选择 2.vmware创建一个虚拟机(centos) 3.安装配置centos7 4.xshell配置连接虚拟机(centos) ...
- 力扣算法——139WordBreak【M】
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine ...
- mysql 日期和时间戳互换
1.日期转时间戳 UNIX_TIMESTAMP('2019-06-25 12:30:00') 2.时间戳转日期 FROM_UNIXTIME(1545711900,'%Y-%m-%d') 3. DAT ...
- nginx中root与alias关键字的区别
前言 近段时间秋招上岸了,于是每天疯狂补各种分布式基础,每天都在痛苦与快乐中度过. 在学习 nginx 的时候,遇到配置上的问题:root 与 alias 的区别,卡了大概三个小时,记录下来警醒自己不 ...
- 配置ssh免密登录问题
有小伙伴的系统需要做免密登录.配置比较简单,ssh-keygen然后生成authorized_keys 文件即可. 但是配置好之后,修改相应用户的家目录权限后,则免密登录就失效了. 经过试验,发现家目 ...
- 为什么要用webpack!
为什么要用webpack? 现今的很多网页其实可以看做是功能丰富的应用,它们拥有着复杂的JavaScript代码和一大堆依赖包. 模块化,让我们可以把复杂的程序细化为小的文件; 类似于Type ...
- 发现最新版百度Android 定位SDK v6.1.3 网络定位bug
对于百度地图已经实在忍无可忍了,实验室两年以前的一个项目用到了百度地图,以前师兄毕业了,我来维护这个破项目,百度地图推出新版本出来后,老版本的api不能用了,不能做到向下兼容吗?换掉少量的api也就算 ...