【数学 思维题】HDU4473Exam
过程很美妙啊
Problem Description
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
For each test case, there is a single line containing only one integer n (1 ≤ n ≤ 1011).
Input is terminated by EOF.
Output
题目大意
求有序三元组$(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的更多相关文章
- PJ考试可能会用到的数学思维题选讲-自学教程-自学笔记
PJ考试可能会用到的数学思维题选讲 by Pleiades_Antares 是学弟学妹的讲义--然后一部分题目是我弄的一部分来源于洛谷用户@ 普及组的一些数学思维题,所以可能有点菜咯别怪我 OI中的数 ...
- 51Nod 1003 阶乘后面0的数量(数学,思维题)
1003 阶乘后面0的数量 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 n的阶乘后面有多少个0? 6的阶乘 = 1*2*3*4*5*6 = 720 ...
- Gym 100801D Distribution in Metagonia (数学思维题)
题目:传送门.(需要下载PDF) 题意:t组数据,每组数据给定一个数ni(1 ≤ ni ≤ 10^18),把ni拆成尽可能多的数,要求每个数的素因子只包含2和3,且这些数不能被彼此整除,输出一共能拆成 ...
- BZOJ4377 Kurs szybkiego czytania \ Luogu 3589[POI2015]KUR - 数学思维题
Solution 我又双叒叕去看题解啦$QAQ$, 真的想不到鸭 输入 $a$ 和 $n$ 互质, 所以满足 $a \times i \ mod \ n$ $(0<=i<n)$ 肯定是不重 ...
- 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串,求出小串在大串中出 ...
- EOJ2018.10 月赛(B 数学+思维题)
传送门:Problem B https://www.cnblogs.com/violet-acmer/p/9739115.html 题意: 找到最小的包含子序列a的序列s,并且序列s是 p -莫干山序 ...
- EOJ2018.10 月赛(A 数学+思维题)
传送门:Problem A https://www.cnblogs.com/violet-acmer/p/9739115.html 题意: 能否通过横着排或竖着排将 1x p 的小姐姐填满 n x m ...
- zoj 2818 Root of the Problem(数学思维题)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2818 题目描述: Given positive integer ...
- HDU5742 It's All In The Mind 数学思维题
Problem Description Professor Zhang has a number sequence a1,a2,...,an. However, the sequence is not ...
随机推荐
- Tomcat乱码问题
问题:淇℃伅 [main] org.apache.catalina.startup.VersionLoggerListener.log Server容器启动乱码--tomcat 解决:修改.tomca ...
- Git 深度学习填坑之旅二(文件三种状态、打标签)
0x01 三种状态 Git 有三种状态,你的文件可能处于其中之一: 已提交(committed).已修改(modified)和已暂存(staged). 已提交表示数据已经安全的保存在本地数据库中. 已 ...
- DOM的学习网站 DOM是HTML和XML的编程接口
- VxWorks实验八 信号
实验八信号1 实验目的1.学习使用信号2 实验内容在实验一建立的 project 中,编写一段信号处理程序,将其与SIGINT 相关连,使用kill()发送SIGINT 信号并调用信号处理程序.观察运 ...
- CodeForces - 500A-New Year Transportation(模拟)
New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, ...
- atcoder square869120Contest#3 F 寿司
省选round1的时候dalao的推荐——atcoder的题目码量不大,但很巧妙,题目比较难找,挂个链冷静一下:http://s8pc-3.contest.atcoder.jp/tasks/s8pc_ ...
- Linux Ubuntu系统之PPP拨号经验分享
近期,工作需要,我负责开发PPP拨号模块. 说起拨号,算算时间,我已经做过2次了, 暴露年龄了,呵呵. 第一次是刚毕业做的PPOE拨号,给电信做拨号软件,在河北石家庄工作过一段时间,基于windows ...
- sql server replace函数巧妙完成字符串联结
示例一: 需求:将'1,2,3,4,5,6,7,8,9,10'转成:'1','2','3','4','5','6','7','8','9','10' ),) set @s='1,2,3,4,5,6,7 ...
- Java微信公众平台开发(十一)--微信JSSDK中Config配置
JSSDK曾经引爆前端以及后端的工程师,其魔性的力量毋庸置疑,在我们的技术眼里它的实现原理和根本是不能够被改变的,这篇文章就不对其js的实现做任何评价和解说了(因为我也不是很懂,哈哈),这里要说的是它 ...
- java 多线程死锁
死锁案例: package com.test; public class DealThread implements Runnable { public String username; public ...