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

The numbers 

113366101015152121282836364545 and t_i=\frac{1}{2}i(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 t_rtr 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\le N\le 10^{16})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 亚洲区(乌鲁木齐赛区)网络赛


题意:给你一个数列,数列通项为 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值