现在的位置: 首页 > 综合 > 正文

hdu – 4342 – History repeat itself – 纯数学水题

2012年04月13日 ⁄ 综合 ⁄ 共 485字 ⁄ 字号 评论关闭

http://acm.hdu.edu.cn/showproblem.php?pid=4342

#include <cstdio>
#include <cmath>
typedef __int64 LL;
LL n, sum, num;
int T;
LL getnum(){
    num = ((2 * n + 1) + sqrt(4 * n + 1)) / 2;
    for(LL i = num; i >= 1; i --){
        if(i - (LL)sqrt(i) == n && (double)(sqrt(i)) - (LL)(sqrt(i)) != 0) {
            num = i; return num;
        }
    }
}
LL getans(){
    LL ans = 0;
    LL tmp = (LL)sqrt(num) - 1;
    ans = (tmp * (2 * tmp + 1) * (tmp + 1) / 3) + tmp * (tmp + 1) / 2 + (num - ( tmp + 1 ) * ( tmp + 1 ) + 1) * (tmp + 1);
    return ans;
}
int main(){
    scanf("%d", &T);
    while(T --){
        scanf("%I64d", &n);getnum();
        printf("%I64d %I64d\n", num, getans());
    }
    return 0;
}

抱歉!评论已关闭.