2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 - E Half-consecutive Numbers

The numbers 113366101015152121282836364545 and ti=12i(i+1)ti=21i(i+1), are called half-consecutive.

For given NN, find the smallest rr which is no smaller than NN such that trtr is square.

Input Format

The input contains multiple test cases.

The first line of a multiple input is an integer TT followed by TT input lines.

Each line contains an integer N (1≤N≤1016)N (1N1016).

Output Format

For each test case, output the case number first.

Then for given NN, output the smallest rr.

If this half-consecutive number does not exist, output −11.

样例输入
4
1
2
9
50
样例输出
Case #1: 1
Case #2: 8
Case #3: 49
Case #4: 288
题目来源

2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛

题意:找出不小于n的最小的i,使ti为平方数。


POINT:

打个表看看,找规律。

11 1

84 9

4925 49

288144 289

1681841 1681

98004900 9801

5712128561 57121


11 1

82 3

495 7

28812 17

168129 41

980070 99

57121169 239

332928408 577

1940449985 1393

113097682378 3363

659181615741 8119

38419920013860 19601

223927704133461 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]);
        
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值