【codeforces 235E】 Number Challenge
http://codeforces.com/problemset/problem/235/E (题目链接)
题意
给出${a,b,c}$,求${\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)}$
extra
有这样一个公式,就是约数个数和那道题的推广吧。$${\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)=\sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^c[gcd(i,j)=gcd(i,k)=gcd(j,k)=1]\lfloor\frac{a}{i}\rfloor\lfloor\frac{b}{j}\rfloor\lfloor\frac{c}{k}\rfloor}$$
然并卵,这个式子我不会证也不会用。。还是直接推吧。
Solution
莫比乌斯反演。
\begin{aligned} \sum_{i=1}^a\sum_{j=1}^b\sum_{k=1}^cd(ijk)=\sum_{i=1}^{ab}f(i)\sum_{j=1}^cd(ij) \end{aligned}
其中${f(n)=\sum_{i=1}^a\sum_{j=1}^b[ab=n]}$。
\begin{aligned} & \sum_{i=1}^{ab}f(i)\sum_{j=1}^cd(ij) \\ =&\sum_{i=1}^{ab}f(i)\sum_{j=1}^c\sum_{u|i}\sum_{v|j}[gcd(u,v)=1] \\ =&\sum_{u=1}^{ab}\sum_{v=1}^c[gcd(u,v)=1]\sum_{i=1}^{\lfloor{ab/u}\rfloor}f(iu)\lfloor\frac{c}{v}\rfloor \end{aligned}
我们令${S(n)=\sum_{i=1}^{\lfloor{ab/n}\rfloor}f(in)}$,并把变量${u,v}$换成${i,j}$,因为${u,v}$看起来太丑了→_→。
\begin{aligned} & \sum_{i=1}^{ab}\sum_{j=1}^c[gcd(i,j)=1]S(i)\lfloor\frac{c}{j}\rfloor \\ =&\sum_{i=1}^{ab}\sum_{j=1}^c\sum_{t|i,t|j}μ(t)S(i)\lfloor\frac{c}{j}\rfloor \\ =&\sum_{t=1}^cμ(t)\sum_{i=1}^{\lfloor{ab/t}\rfloor}S(it)\sum_{j=1}^{\lfloor{c/t}\rfloor}\lfloor\frac{c}{jt}\rfloor \end{aligned}
看到这个式子是不是感到了满满的套路,我们故技重施,令${P(n)=\sum_{i=1}^{\lfloor{ab/n}\rfloor}S(in)}$,${Q(n)=\sum_{i=1}^n\lfloor\frac{n}{i}\rfloor}$
\begin{aligned} \sum_{t=1}^cμ(t)P(t)Q(\lfloor\frac{c}{t}\rfloor) \end{aligned}
这样,我们${O(ab)}$的求出${f}$,之后按顺序${O(ab\log ab)}$的求出${S}$和${P}$,然后${O(c^2)}$的求出${Q}$,当然如果想分段也可以分段。最后只需要从${1}$枚举到${c}$就可以得出答案了。
细节
时限卡得有点紧,你需要常数优化→_→
代码
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#define LL long long
#define inf 2147483640
#define MOD (1ll<<30)
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; const int maxn=4000010,maxm=2010;
LL s[maxn],f[maxn],P[maxm],Q[maxm];
int a,b,c,p[maxm],vis[maxm],mu[maxm]; void inc(LL &a,LL b) {
a+=b;if (a>MOD) a-=MOD;
}
int main() {
scanf("%d%d%d",&a,&b,&c);
mu[1]=1;
for (int i=2;i<=c;i++) {
if (!vis[i]) p[++p[0]]=i,mu[i]=-1;
for (int j=1;j<=p[0] && i*p[j]<=c;j++) {
vis[i*p[j]]=1;
if (i%p[j]==0) {mu[i*p[j]]=0;break;}
else mu[i*p[j]]=-mu[i];
}
}
for (int i=1;i<=a;i++)
for (int j=1;j<=b;j++) f[i*j]++;
for (int i=1;i<=a*b;i++)
for (int j=1;j<=a*b/i;j++) inc(s[i],f[i*j]);
for (int i=1;i<=c;i++)
for (int j=1;j<=a*b/i;j++) inc(P[i],s[i*j]);
for (int i=1;i<=c;i++)
for (int j=1;j<=i;j++) inc(Q[i],i/j);
LL ans=0;
for (int i=1;i<=c;i++)
ans=(ans+mu[i]*P[i]*Q[c/i]%MOD)%MOD;
printf("%lld",(ans+MOD)%MOD);
return 0;
}
【codeforces 235E】 Number Challenge的更多相关文章
- 【Codeforces 466C】Number of Ways
[链接] 我是链接,点我呀:) [题意] 让你把数组分成3个连续的部分 每个部分的和要一样 问你有多少种分法 [题解] 先处理出来num[i] 表示i..n这里面有多少个j 满足aft[j] = af ...
- 【CodeForces 660D】Number of Parallelograms(n个点所能组成的最多平行四边形数量)
You are given n points on a plane. All the points are distinct and no three of them lie on the same ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 514A】Chewbaсca and Number
[题目链接]:http://codeforces.com/contest/514/problem/A [题意] 允许你把每个数字翻转 ->x变成9-x 然后问你能够变成的最小的数字是什么; 不能 ...
- 【codeforces 805D】Minimum number of steps
[题目链接]:http://codeforces.com/contest/805/problem/D [题意] 给你一个字符串; 里面只包括a和b; 让你把里面的"ab"子串全都去 ...
- 【codeforces 546D】Soldier and Number Game
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 768C】Jon Snow and his Favourite Number
[题目链接]:http://codeforces.com/contest/768/problem/C [题意] 给你n个数字; 让你每次把这n个数字排序; 然后对奇数位的数字进行异或操作,然后对新生成 ...
- 【26.67%】【codeforces 596C】Wilbur and Points
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 766B】Mahmoud and a Triangle
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- python 基础篇01
一.python介绍年的圣诞节期间,吉多亿个文件的上传和下载千万张照片被分享,全部用倍年,为了打发圣诞节假期,年,第一个Python编译器诞生.它是用C语言实现的,并能够调用C语言的库文件.从一出生, ...
- Netty源码分析第5章(ByteBuf)---->第10节: SocketChannel读取数据过程
Netty源码分析第五章: ByteBuf 第十节: SocketChannel读取数据过程 我们第三章分析过客户端接入的流程, 这一小节带大家剖析客户端发送数据, Server读取数据的流程: 首先 ...
- HackRF 无线门铃信号录制与重放
本文内容.开发板及配件仅限用于学校或科研院所开展科研实验! 淘宝店铺名称:开源SDR实验室 HackRF链接:https://item.taobao.com/item.htm?spm=a1z10.1- ...
- 投稿007期|令人震惊到发指的PyObject对象代码设计之美
前言 最近在重温经典漫画<SlamDunk>的全国大赛篇,其中的一个情形可以很好的诠释虎躯一震这个状态——当樱木看到流川枫一次高难度投篮时内心的感受:“经过两万次射球练习后,樱木首次明白到 ...
- 定时任务crone表达式demo
1. cron表达式格式: {秒数} {分钟} {小时} {日期} {月份} {星期} {年份(可为空)} 2. cron表达式各占位符解释: {秒数} ==> 允许值范围: 0~59 ,不允许 ...
- python之模块_随手记录的模块
目录 1.StringIO模块 2.string模块 3.pprint模块 4.struct模块 5.uuid模块 6.itertools 7.prettytable 1.StringIO (1)使用 ...
- centos下设置自启动和配置环境变量的方法
1. 设置自启动 在CentOS系统下,主要有两种方法设置自己安装的程序开机启动.1.把启动程序的命令添加到/etc/rc.d/rc.local文件中,比如下面的是设置开机启动httpd. #!/bi ...
- Scrum Meeting 11.09
成员 今日任务 明日计划 用时 徐越 解决bug:可以重复点赞:answer被选为best answer后点赞数归零:首页不能正确显示问题的回复数.修改搜索功能的代码 继续测试相关app功能,如果达 ...
- 2-Seventh Scrum Meeting20151207
任务分配 闫昊: 今日完成:完成数据库设计. 明日任务:和唐彬讨论接口如何在android实现. 唐彬: 今日完成:读了IOS讨论区后台接口. 明日任务:和闫昊讨论接口如何在android实现. 史烨 ...
- Daily Scrumming* 2015.10.28(Day 9)
一.总体情况总结 今日项目总结: 1.前后端同一了API设计以及API权限认证.用户状态保存的开发方案 2.API以及后端模型已经开始开发,前端UEditor开始学习,本周任务有良好的起步 3.前后端 ...