过程很美妙啊

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

【数学 思维题】HDU4473Exam的更多相关文章

  1. PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记

    PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...

  2. 51Nod 1003 阶乘后面0的数量(数学,思维题)

    1003 阶乘后面0的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 5         难度:1级算法题 n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720 ...

  3. Gym 100801D Distribution in Metagonia (数学思维题)

    题目:传送门.(需要下载PDF) 题意:t组数据,每组数据给定一个数ni(1 ≤ ni ≤ 10^18),把ni拆成尽可能多的数,要求每个数的素因子只包含2和3,且这些数不能被彼此整除,输出一共能拆成 ...

  4. BZOJ4377 Kurs szybkiego czytania \ Luogu 3589[POI2015]KUR - 数学思维题

    Solution 我又双叒叕去看题解啦$QAQ$, 真的想不到鸭 输入 $a$ 和 $n$ 互质, 所以满足 $a \times i \ mod \ n$ $(0<=i<n)$ 肯定是不重 ...

  5. BZOJ4377[POI2015]Kurs szybkiego czytania——数学思维题

    题目描述 给定n,a,b,p,其中n,a互质.定义一个长度为n的01串c[0..n-1],其中c[i]==0当且仅当(ai+b) mod n < p.给定一个长为m的小01串,求出小串在大串中出 ...

  6. EOJ2018.10 月赛(B 数学+思维题)

    传送门:Problem B https://www.cnblogs.com/violet-acmer/p/9739115.html 题意: 找到最小的包含子序列a的序列s,并且序列s是 p -莫干山序 ...

  7. EOJ2018.10 月赛(A 数学+思维题)

    传送门:Problem A https://www.cnblogs.com/violet-acmer/p/9739115.html 题意: 能否通过横着排或竖着排将 1x p 的小姐姐填满 n x m ...

  8. zoj 2818 Root of the Problem(数学思维题)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2818 题目描述: Given positive integer ...

  9. HDU5742 It's All In The Mind 数学思维题

    Problem Description Professor Zhang has a number sequence a1,a2,...,an. However, the sequence is not ...

随机推荐

  1. VMWare虚拟机Windows下的下载与安装

    原文链接:http://www.studyshare.cn/blog-front//software/details/1161/0一.下载此处收集各种开发工具软件,供下载官网下载:https://ww ...

  2. LDAP理论知识

    整理改编自: https://www.cnblogs.com/yjd_hycf_space/p/7994597.html http://blog.51cto.com/407711169/1439623 ...

  3. Maven项目编译版本的问题和Spring中没有导入核心包

    idea中maven项目的编译: 方案1:maven的settings.xml中指定全局默认编译版本 <profile> <id>jdk-1.8</id> < ...

  4. Nginx功能介绍

    Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的. 从2004年发布至今,凭借开元的力量,已经接近成熟与完善. Nginx功能丰富,可作为HTTP服务器,也可作 ...

  5. 管道是如何随着WebHost的开启被构建出来的?

    管道是如何随着WebHost的开启被构建出来的? 注册的服务器和中间件共同构成了ASP.NET Core用于处理请求的管道, 这样一个管道是在我们启动作为应用宿主的WebHost时构建出来的.要深刻了 ...

  6. openstack修改增加网卡及更改ip

        1.neutron更改及mysql数据库更改网卡及ip:     neutron port-update ae22c84b-22a9-4618-b046-1eb61379bcea  --all ...

  7. Python网络编程中的服务器架构(负载均衡、单线程、多线程和同步、异步等)

    这篇文章主要介绍服务器架构. 网络服务需要面对两个挑战. 第一个问题是核心挑战,要编写出能够正确处理请求并构造合适响应的代码. 第二个挑战是如何将网络代码部署到随系统自动启动的Windows服务或者是 ...

  8. Uncaught Error: Bootstrap's JavaScript requires jQuery

    在写bootstarp的时候,一直报 Uncaught Error: Bootstrap's JavaScript requires jQuery 查看了自己引入的文件路径是对的,也可以使用jquer ...

  9. 《C#高效编程》读书笔记01-使用属性而不是可访问的数据成员

    在需求变更中,属性比数据成员更容易修改,例:客户对象不该与空白名称,若你使用公有属性封装Name,那么现在修改一处,而数据成员则可能要修改多处 public class Customer { priv ...

  10. Css+Html

    CSS样式 <style type="text/css"> tt.tt1 { <style type="text/css"> p { b ...