tju3772. Rupxup's Math Problem

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)个。
所以主要部分代码为:
LL f(LL n)
{
    if (n<=5) return a[n];
    LL sum = 0;
    int i;
    for (i = 1; i*i <= n; ++i)
    {
        sum += m/i - (i - 1);
    }
    return sum*2-i+1;
}
瞬间复杂度降到了根号n,,是不是很666666666666

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值