【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;
            }
        }
    }
}

發佈了323 篇原創文章 · 獲贊 119 · 訪問量 21萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章