【2017新疆网络赛】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
题意:
  ti=12i(i+1)ti=21i(i+1),给出N,求r>N且tr为完全平方数的最小r。
思路:

打表。必须i为完全平方数且(i+1)/2为完全平凡数。


//
//  main.cpp
//  E
//
//  Created by zc on 2017/9/14.
//  Copyright © 2017年 zc. All rights reserved.
//

#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long 
using namespace std;

ll a[21]={1,8,49,288,1681,9800,57121,332928,1940449,11309768,65918161,384199200,2239277041,13051463048,76069501249,443365544448,2584123765441,15061377048200,87784138523761,511643454094368,2982076586042449};

int main(int argc, const char * argv[]) {
    /*for(ll i=1;i<=100000000;++i)
    {
        ll j=i*i;
        if(!(j&1)) continue;
        ll t=(j-1)>>1;
        ll st=sqrt(t);
        if(st*st==t)    printf("%lld,",j-1);
        t=(j+1)>>1;
        st=sqrt(t);
        if(st*st==t)    printf("%lld,",j);
    }*/
    int T,kase=0;
    scanf("%d",&T);
    while(T--)
    {
        ll n;
        scanf("%lld",&n);
        for(int i=0;i<21;i++)
        {
            if(a[i]>=n)
            {
                printf("Case #%d: %lld\n",++kase,a[i]);
                break;
            }
        }
    }
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值