您的位置:首页 > 其它

2012 #5 History repeat itself

2015-08-30 19:40 543 查看
History repeat itself
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status Practice HDU 4342

Description

Tom took the Discrete Mathematics course in the 2011,but his bad attendance angered Professor Lee who is in charge of the course. Therefore, Professor Lee decided to let Tom face a hard probability problem, and announced that if he fail to slove the problem there would be no way for Tom to pass the final exam.
As a result , Tom passed.
History repeat itself. You, the bad boy, also angered the Professor Lee when September Ends. You have to faced the problem too.
The problem comes that You must find the N-th positive non-square number M and printed it. And that's for normal bad student, such as Tom. But the real bad student has to calculate the formula below.

#include <stdio.h>
#include <string.h>

long long a[70007],b[70007];
int main()
{
int T;
long long i,j,k;
long long  n;
scanf("%d",&T);
a[0]=0;
for(i=1;i<=70000;i++)
{
a[i]=a[i-1]+i*(i*2+1);
}
for(i=1;i<=70000;i++)
{
b[i]=i*i-i+1;
}
while(T--)
{
scanf("%I64d",&n);
for(i=1;i<=70000;i++)
{
if(n<b[i])
{
i--;
break;
}
}
long long x=(n-b[i]+1)+i*i,y=a[i-1]+i*(n-b[i]+2);
printf("%I64d %I64d\n",x,y);
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: