过程很美妙啊
Problem Description
Rikka is a high school girl suffering seriously from Chūnibyō (the age of fourteen would either act like a know-it-all adult, or thinks they have special powers no one else has. You might google it for detailed explanation) who, unfortunately, performs badly at math courses. After scoring so poorly on her maths test, she is faced with the situation that her club would be disband if her scores keeps low.
Believe it or not, in the next exam she faces a hard problem described as follows.
Let’s denote f(x) number of ordered pairs satisfying (a * b)|x (that is, x mod (a * b) = 0) where a and b are positive integers. Given a positive integer n, Rikka is required to solve for f(1) + f(2) + . . . + f(n).
According to story development we know that Rikka scores slightly higher than average, meaning she must have solved this problem. So, how does she manage to do so?
Believe it or not, in the next exam she faces a hard problem described as follows.
Let’s denote f(x) number of ordered pairs satisfying (a * b)|x (that is, x mod (a * b) = 0) where a and b are positive integers. Given a positive integer n, Rikka is required to solve for f(1) + f(2) + . . . + f(n).
According to story development we know that Rikka scores slightly higher than average, meaning she must have solved this problem. So, how does she manage to do so?
Input
There are several test cases.
For each test case, there is a single line containing only one integer n (1 ≤ n ≤ 1011).
Input is terminated by EOF.
For each test case, there is a single line containing only one integer n (1 ≤ n ≤ 1011).
Input is terminated by EOF.
Output
For each test case, output one line “Case X: Y” where X is the test case number (starting from 1) and Y is the desired answer.
题目大意
求有序三元组$(a,b,c)$满足$a*b*c=n$的个数
题目分析
考虑以下三种做法:
大力卷积吧!
发现$\sum_{abc=n} \textbf{1}$这是一个卷积的形式,那么卷两次即可。
时间复杂度:$O(n\ln n)$
线性筛
注意到$n$的质因数之间互不影响。那么考虑将$n$分解为$n=p_1^{a_1}\times p_2^{a_2}\times \cdots \times p_k^{a_k}$的形式,于是答案就是${\rm f(n)}={(a_1+1)\times (a_1+2)\over{2}}\times {(a_2+1)\times (a_2+2)\over{2}}\times \cdots \times {(a_k+1)\times (a_k+2)\over{2}}$.
这样子做一遍线性筛就好了。
时间复杂度:$O(n)$
转化一下
注意到这个顺序实际上不是必要的,也就是说完全可以算出无序的答案之后反过来考虑有序,即$abc≤n$的答案数.
那么只需要枚举$a,b$,就可以得到$c$的范围即$[b,{\left \lfloor \frac{n}{ab} \right \rfloor}]$。
此时若$a=b$,如果$c=b$会产生1种方案;$c≠b$有${\left \lfloor \frac{n}{ab} \right \rfloor}-b$种情况、而每一种情况会产生3种方案。这里所谓产生的方案即有序所带来的额外贡献。那么$a≠b$时同理。
时间复杂度:$O(n^{\frac{2}{3}})$
#include<bits/stdc++.h>
typedef long long ll; ll n,ans;
int scenario; int main()
{
while (scanf("%lld",&n)!=EOF)
{
ans = ;
for (ll i=; i*i*i<=n; i++)
for (ll j=i; i*j*j<=n; j++)
{
ll k = n/(i*j);
if (j > k) break;
if (i==j) ans += (k-j)*3ll+;
else ans += (k-j)*6ll+;
}
printf("Case %d: %lld\n",++scenario,ans);
}
return ;
}
END