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
题目来源
题意:给你一个数列,数列通项为 1/2*(i)*(i+1) ,给你一个i,问你在i之后包括i,的第一个平方数是第几个。
解题思路:我是直接查查出来的……然后里面有详细的解释……http://oeis.org/search?q=1%2C8%2C49%2C288&language=english&go=Search
#include<iostream>
#include<deque>
#include<memory.h>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#define INF 1<<29
using namespace std;
long long int ans[100];
void init()
{
ans[0]=1;
ans[1]=8;
ans[2]=49;
ans[3]=288;
ans[4]=1681;
ans[5]=9800;
ans[6]=57121;
ans[7]=332928;
ans[8]=1940449;
ans[9]=11309768;
ans[10]=65918161;
ans[11]=384199200;
ans[12]=2239277041;
ans[13]=13051463048;
ans[14]=76069501249;
ans[15]=443365544448;
ans[16]=2584123765441;
ans[17]=15061377048200;
ans[18]=87784138523761;
ans[19]=511643454094368;
ans[20]=2982076586042449;
ans[21]=17380816062160328;
}
int main()
{
long long int t;
scanf("%lld", &t);
long long int N;
init();
for(long long int qqq=1;qqq<=t;qqq++)
{
scanf("%lld",&N);
for(int i=0;i<22;i++)
if(ans[i]>=N){
printf("Case #%lld: %lld\n",qqq,ans[i]);
break;
}
}
return 0;
}