HDU4342 History repeat itself

History repeat itself


Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1387 Accepted Submission(s): 625


Problem 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.


So, that you can really understand WHAT A BAD STUDENT YOU ARE!!


Input
There is a number (T)in the first line , tell you the number of test cases below. For the next T lines, there is just one number on the each line which tell you the N of the case.
To simplified the problem , The N will be within 231 and more then 0.


Output
For each test case, print the N-th non square number and the result of the formula.


Sample Input
4
1
3
6
10


Sample Output
2 2
5 7
8 13
13 28


Author
HIT


Source
2012 Multi-University Training Contest 5

题意:要求找到第n个除了平方数的数m,然后计算个1-m的根号和。

一个比较简单的数学题,sqr里保存的是到达这个平方数的时候有多少个不是平方数的数,就是i*i-i,然后就是数学题了。。。。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll __int64
using namespace std;
const int MAXN=100010;
ll sqr[MAXN],sum[MAXN];
int main()
{
    ll i;
    int n,t;
    sqr[0]=sum[0]=0;
    for(i=1;i<=100000;i++)
    {
        sqr[i]=i*i-i;
        sum[i]=sum[i-1]+((sqr[i]+i)-(sqr[i-1]+i-1)-1)*(i-1)+i;
    }
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(i=1;i<=100000;i++)
            if(sqr[i]>=n)
            break;
        ll ans1=sqr[i]+i-(sqr[i]-n+1);
        ll ans2=sum[i-1]+(ans1-(sqr[i-1]+i-1))*(i-1);
        printf("%I64d %I64d\n",ans1,ans2);
    }
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值