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)个。
所以主要部分代码为:
瞬间复杂度降到了根号n,,是不是很666666666666LL 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; }