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 ...
随机推荐
- Linux中的特殊权限s、t、i、a
文件权限除了r.w.x外还有s.t.i.a权限:s:文件属主和组设置SUID和GUID,文件在被设置了s权限后将以root身份执行.在设置s权限时文件属主.属组必须先设置相应的x权限,否则s权限并不能 ...
- PHP代码审计基础
php核心配置 php.ini 基本配置 语法 大小写敏感 运算符 空值的表达式 安全模式 安全模式 safe_mode = off 用来限制文档的存取,限制环境变量的存取,控制外部程序的执行.PHP ...
- ROW_NUMBER() over(order by ID desc ) as RowNumber 返回类型问题
因为ID是int类型,所以ROW_NUMBER() over(order by ID desc ) as RowNumber 想当然的认为是Int类型 实际ROW_NUMBER() over(orde ...
- 自定义servlet重写doGet或者doPost方法时,405 method not allowed
自定义servlet public class TestServlet extends HttpServlet { @Override protected void doGet(HttpServlet ...
- 隐式激活Activity
- LeetCode Array Medium 11. Container With Most Water
Description Given n non-negative integers a1, a2, ..., an , where each represents a point at coordin ...
- 【记录】安装mysql Install/Remove of the Service Denied!错误的解决办法
最近安装 Mysql 5.6版本,在安装的过程中出现Install/Remove of the Service Denied!错误!(本人Win10 系统) 出现此问题是由于当前用户权限不够,需要以管 ...
- Stm32CubeMX5 配置使用ADC
试验,通过ADC按键 按下时的不同电压,然后把相应的数字量通过串口发出, 1. 使用 ADC 检测按键, 原理图分析 2. Stm32CubeMX5配置 ADC功能,先配置PA0为ADC模式 配置 A ...
- 使用appium1.4在android8.0真机上测试程序时报错command failed shell "ps 'uiautomator'"的解决方式
appium1.4,运行自动化脚本时提示 org.openqa.selenium.SessionNotCreatedException: A new session could not be crea ...
- linux中python3的安装
yum -y install openssl-devel #要使用pip3需要安装这个软件tar xf Python-3.5.6.tgz cd Python-3.5.6 ./configure --p ...