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 ...
随机推荐
- Gson extend 思路
package org.rx.core.internal; import com.google.gson.*; import net.sf.cglib.proxy.Enhancer; import n ...
- Java 线程基础
Java 线程基础
- [bzoj4589]Hard Nim(FWT快速沃尔什变化+快速幂)
题面:https://www.lydsy.com/JudgeOnline/problem.php?id=4589 题意 求选恰好n个数,满足每个数都是不大于m的质数,且它们的异或和为0的方案数. 解法 ...
- Java对象相等比较(Equals)
以下代码显示如何实现equals()和hashCode()方法 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...
- VS2008的使用
文章转载自:http://www.cnblogs.com/aduck/archive/2011/11/11/2245460.html 1.如何在vc2008中显示行号 中文版: 菜单-工具-选项 在新 ...
- python获取每日涨跌停股票统计,封闭时间和打开次数
接口:limit_list 描述:获取每日涨跌停股票统计,包括封闭时间和打开次数等数据,帮助用户快速定位近期强(弱)势股,以及研究超短线策略. 限量:单次最大1000,总量不限制 积分:用户积2000 ...
- 代码编译与反编译 (.py文件与.pyc文件互转)
# 将.py文件转化为.pyc文件,实现代码隐藏的需要,转化后的.pyc文件将在当前目录的__pycache__文件夹下. # .pyc文件的使用与.py文件的使用相同. .py -> .pyc ...
- android中的BroadCastReceiver
BroadCastReceiver组件本质是一种全局的监听器,用于监听系统全局的广播消息.由于BroadCastReceiver是一种全局的监听器,因此他可以非常方便的实现系统之间不同组件之间的通信. ...
- 《node.js开发指南》partial is not defined的解决方案
由于ejs的升级,<node.js开发指南>中使用的 partial 函数已经摒弃,使用foreach,include代替 原来的代码是: <%- partial('listitem ...
- 带你看懂LayoutInflater中inflate方法
关于inflate问题,我想很多人多多少少都了解一点,网上也有很多关于这方面介绍的文章,但是枯燥的理论或者翻译让很多小伙伴看完之后还是一脸懵逼,so,我今天想通过三个案例来让小伙伴彻底的搞清楚这个东东 ...