Description
定义 ti=i(i+1)2 t i = i ( i + 1 ) 2 ,给出 n n ,问不小于的数中满足 tr t r 是完全平方数的最小的 r r
Input
第一行一整数表示用例组数,每组用例输入一整数 n n
Output
输出满足 tr t r 是完全平方数的最小 r r ,如果不存在则输出
Sample Input
4
1
2
9
50
Sample Output
Case #1: 1
Case #2: 8
Case #3: 49
Case #4: 288
Solution
首先求出满足 a(a+1)2=b2 a ( a + 1 ) 2 = b 2 的解 (a,b) ( a , b ) ,由于 (a,a+1)=1 ( a , a + 1 ) = 1 ,如果 a a 为偶数,则,说明 a2 a 2 和 a+1 a + 1 都是完全平方数,设 a=2x2,a+1=y2 a = 2 x 2 , a + 1 = y 2 ,其中 y y 为奇数,则问题转化为求满足是完全平方数的奇数 y y ,如果是奇数,则 (a,a+12)=1 ( a , a + 1 2 ) = 1 ,说明 a,a+12 a , a + 1 2 都是完全平方数,设 a=y2,a+1=2x2 a = y 2 , a + 1 = 2 x 2 ,其中 y y 为奇数,则问题转化为求满足是完全平方数的奇数 y y ,综合上面两种情况,枚举奇数可找到所有满足条件的 a a <script type="math/tex" id="MathJax-Element-31">a</script>,在一个较大范围内枚举打表即可
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
map<ll,int>m;
int check(ll n)
{
int m=(int)sqrt(n+0.5);
if((ll)m*m==n)return 1;
return 0;
}
ll a[]={
1,
8,
49,
288,
1681,
9800,
57121,
332928,
1940449,
11309768,
65918161,
384199200,
2239277041,
13051463048,
76069501249,
443365544448,
2584123765441,
15061377048200,
87784138523761,
511643454094368,
2982076586042449,
17380816062160328};
int main()
{
//for(int i=1;i<=2e8;i+=2)
//{
// if(check(((ll)i*i-1)/2))printf("%I64d,\n",(ll)i*i-1);
// if(check(((ll)i*i+1)/2))printf("%I64d,\n",(ll)i*i);
//}
int T,Case=1;
ll n;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
int pos=lower_bound(a,a+24,n)-a;
printf("Case #%d: %lld\n",Case++,a[pos]);
}
return 0;
}