TOJ 3772.Rupxup's Math Problem

4 篇文章 0 订阅
3 篇文章 0 订阅

题目链接:http://acm.tju.edu.cn/toj/showp3772.html



Description

Rupxup has learned a new function called function "F(n)", where F(n) equals to the number of factors of n (including 1 and n). For example, F(1) = 1, F(4) = 3, ... Now if you ask Rupxup to calculate F(n), he may soon tell you the answer. If you are evil enough and ask him about the sum of the first k F(i): (F(1) + F(2) + .. + F(k) = G(k)), I believe out superbrother Rupxup will soon tell you the answer too!

Input

In the first line there is an integer T, indicates the number of test cases. (T ≤ 100) In each case, the first line contains only one integer k. (1 ≤ k ≤ 109).

Output

Just output G(k).

Sample Input

3
1
2
3

Sample Output

1
3
5
 
 
,,这题太劲了,,一开始的想法就是分段打表,结果还是有点难写,,然后一不小心瞄到标程上数形结合这4个大字,,惊呆了。。。
简单说下思路
先思考x*y = n这条双曲线,,显然在第一象限分支中下方的整点的横纵坐标相乘必定小于n,那这一对数字必定代表一个小于n的数的一对约数。
作直线x=y,于是可以先计算含x=y这条直线的双曲线下方整点的个数。
x=1的时候有n个,x=2的时候有n/2-1个。。。
于是乘以2。
然后x=y这条直线上的i-1个点多计算了一次,于是要减去(i-1)个。
代码为:


#include <stdio.h>
long long f(int m)
{
    long long sum=0,i;
    for(i=1;i*i<=m;i++)
        sum+=m/i-i+1;
    return sum*2-i+1;
}
int main()
{
    int t,k;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&k);
        printf("%lld\n",f(k));
    }
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值