过程很美妙啊

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?

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.

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

最新文章

  1. 从单幅图像高质量去除运动模糊——读JiaYaJia同名英文论文总结
  2. Amazon全场满$35减$5 (需Facebook)
  3. 【转】两分钟彻底让你明白Android Activity生命周期(图文)!----不错
  4. My Solution: Word Ladder
  5. Raspberry Pi 上使用WN725N连接WIFI
  6. 设置Sql server用户对表、视图、存储过程、架构的增删改查权限
  7. JS中的 map, filter, some, every, forEach, for...in, for...of 用法总结
  8. Activi相关表归纳
  9. systemd 编写服务管理脚本---学习
  10. 现代编译原理——第六章:中间树 IR Tree 含源码
  11. flask-sqlalchemy 一对一,一对多,多对多操作
  12. JN5139 zigbee 资料
  13. 第 8 章 容器网络 - 070 - 如何定制 Calico 网络 Policy?
  14. libvirt工具实现虚拟机管理
  15. 微信、支付宝App支付-JPay0.0.2发布
  16. Ansible 使用 Playbook 安装 Nginx
  17. 通过phantomjs 进行页面截图
  18. 【资源】分享一个最新版sublime 3143的注册码,亲测可用
  19. sql 日期类型可以使用大于、小于号直接进行比较运算
  20. python初学者随笔Week2

热门文章

  1. RPC00
  2. [LOJ 2070] 「SDOI2016」平凡的骰子
  3. Educational Codeforces Round 65 (Rated for Div. 2) C. News Distribution
  4. NetCore组件
  5. docker jetty启动时报错 failed setting default capabilities.
  6. 运行node提示:events.js:160 throw er; // Unhandled &#39;error&#39; event
  7. Swagger 2.0 集成配置
  8. springmvc httprequest 使用@Autowired注解
  9. 关于一次性的数据输入,excel字符串连接保存到服务器还是CRUD?
  10. RHEL6.4 安装 highpoint RocketRAID 2720 阵列卡驱动