标签:
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4342
题意:
就是要求第a个非平方数是什么
分析:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
#define LL long long
int t;
LL n,idx,ans;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
idx=(LL)ceil((1+sqrt(1+4.0*n))/2)-1+n;
LL k=idx-n;
LL sum=k*idx;
LL tmp=(1+k)*k*(2*k+1)/6-k;
ans=sum-tmp;
cout<<idx<<" "<<ans<<endl;
}
return 0;
}HDU4342 History repeat itself数学规律题
标签:
原文地址:http://blog.csdn.net/bigbigship/article/details/44244449