The numbers 1, 3, 6, 10, 15, 21, 28, 36, 45 and t i = 1 2 i ( i + 1 ) t_i=\frac{1}{2}i(i+1) ti=21i(i+1)are called half-consecutive.
For given N, find the smallest r which is no smaller than N such that t r t_r tr is square.
Input Format
The input contains multiple test cases.
The first line of a multiple input is an integer T followed by T input lines.
Each line contains an integer N ( 1 ≤ N ≤ 1 0 16 ) N ( 1 ≤ N ≤ 1 0 16 ) N~(1\le N\le 10^{16})N (1≤N≤10 ^{16}) N (1≤N≤1016)N(1≤N≤1016).
Output Format
For each test case, output the case number first.
Then for given NN, output the smallest r.
If this half-consecutive number does not exist, output -1.
样例输入
4
1
2
9
50
样例输出
Case #1: 1
Case #2: 8
Case #3: 49
Case #4: 288
题意
像1, 3, 6, 10, 15, 21, 28, 36, 45 and t i = 1 2 i ( i + 1 ) t_i=\frac{1}{2}i(i+1) ti=21i(i+1)的数叫做half-consecutive,现给你一个N要你求出比N大最小的r,这个r是一个half-consecutive的下标,且这个 t r t_r tr 是一个平方数
思路
这样的数其实叫做三角平方数
根据百度百科[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KMMdKyQL-1601531419508)(https://gss3.bdstatic.com/-Po3dSag_xI4khGkpoWK1HF6hhy/baike/s=207/sign=02746d4f6e09c93d03f209f7a83cf8bb/e7cd7b899e510fb3c44750d6d033c895d1430c10.jpg)]直接枚举k来打表即可,因为N的范围不超过long long这样的数大概就只有20+个
最后我们打表得到
long long a[]={1,8,49,288,1681,9800,57121,332928,1940449,11309768,65918161,384199200,2239277041,13051463048,76069501249,443365544448,2584123765441,15061377048200,87784138523761,511643454094368,2982076586042449};
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
long long a[]={1,8,49,288,1681,9800,57121,332928,1940449,11309768,65918161,384199200,2239277041,13051463048,76069501249,443365544448,2584123765441,15061377048200,87784138523761,511643454094368,2982076586042449};
int main()
{
int t,cas=1;
scanf("%d",&t);
while(t--)
{
long long n;
scanf("%lld",&n);
printf("Case #%d: ",cas++);
printf("%lld\n",a[lower_bound(a,a+21,n)-a]);
}
return 0;
}