The numbers 1, 3, 6, 10, 15, 21, 28, 36, 45 and ti=21i(i+1), are called half-consecutive.
For given N, find the smallest r which is no smaller than N such that 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≤1016).
Output Format
For each test case, output the case number first.
Then for given N, 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
题目来源
题意:找出不小于n的最小的i,使ti为平方数。
POINT:
打个表看看,找规律。
1:1 1
8:4 9
49:25 49
288:144 289
1681:841 1681
9800:4900 9801
57121:28561 57121
1:1 1
8:2 3
49:5 7
288:12 17
1681:29 41
9800:70 99
57121:169 239
332928:408 577
1940449:985 1393
11309768:2378 3363
65918161:5741 8119
384199200:13860 19601
2239277041:33461 47321
代码:
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
typedef long long LL;
using namespace std;
void dabiao()
{
LL a,b;
a=1,b=1;
LL i=1;
int cnt=1;
printf("a[%d]=%lld;\n",cnt,i);
while(i<1e16)
{
cnt++;
LL aa=a;
a=a+b;
b=aa+a;
if(cnt&1)
{
i=a*a;
i=i*2-1;
printf("a[%d]=%lld;\n",cnt,i);
}
else
{
i=a*a;
i=i*2;
printf("a[%d]=%lld;\n",cnt,i);
}
}
}
LL a[33];
void init()
{
a[1]=1;
a[2]=8;
a[3]=49;
a[4]=288;
a[5]=1681;
a[6]=9800;
a[7]=57121;
a[8]=332928;
a[9]=1940449;
a[10]=11309768;
a[11]=65918161;
a[12]=384199200;
a[13]=2239277041;
a[14]=13051463048;
a[15]=76069501249;
a[16]=443365544448;
a[17]=2584123765441;
a[18]=15061377048200;
a[19]=87784138523761;
a[20]=511643454094368;
a[21]=2982076586042449;
a[22]=17380816062160328;
a[23]=99999999999999999;
}
int main()
{
int T;
scanf("%d",&T);
init();
int p=0;
while(T--)
{
p++;
LL x;
scanf("%lld",&x);
int i;
for(i=1;i<=23;i++)
{
if(a[i]>=x)
{
break;
}
}
printf("Case #%d: %lld\n",p,a[i]);
}
}