●BZOJ 3561 DZY Loves Math VI
题链:
http://www.lydsy.com/JudgeOnline/problem.php?id=3561
题解:
莫比乌斯反演
$$\begin{aligned}
ANS&=\sum_{i=1}^{n}\sum_{j=1}^{m}lcm(i,j)^{gcd(i,j)}\\
&=\sum_{g=1}^{min(n,m)}\sum_{i=1}^{\frac{n}{g}}\sum_{j=1}^{\frac{m}{g}}g^gi^gj^g[gcd(i,j)==1]\\
&=\sum_{g=1}^{min(n,m)}g^g\sum_{i=1}^{\frac{n}{g}}\sum_{j=1}^{\frac{m}{g}}i^gj^g\sum_{d|gcd(i,j)}\mu(d)\\
&=\sum_{g=1}^{min(n,m)}g^g\sum_{d=1}^{min(\frac{n}{g},\frac{m}{g})}\mu(d) \sum_{i=1}^{\frac{n}{gd}}(id)^g\sum_{j=1}^{\frac{m}{gd}}(jd)^g\\
&=\sum_{g=1}^{min(n,m)}g^g\sum_{d=1}^{min(\frac{n}{g},\frac{m}{g})}\mu(d)\times d^{2g} \sum_{i=1}^{\frac{n}{gd}}i^g\sum_{j=1}^{\frac{m}{gd}}j^g\\
\end{aligned}$$
上面这个式子直接$O(NlogN)$计算就好了。
代码:
#include<bits/stdc++.h>
#define MAXN 500050
using namespace std;
const int mod=1000000007;
int mu[MAXN],mi[MAXN],smi[MAXN];
int Pow(int a,int b){
int ret=1;
while(b){
if(b&1) ret=1ll*ret*a%mod;
b>>=1; a=1ll*a*a%mod;
}
return ret;
}
void Sieve(){
static bool np[MAXN];
static int prime[MAXN],pnt;
mu[1]=1;
for(int i=2;i<=500000;i++){
if(!np[i]) prime[++pnt]=i,mu[i]=-1;
for(int j=1;j<=pnt&&i<=500000/prime[j];j++){
np[i*prime[j]]=1;
if(i%prime[j]) mu[i*prime[j]]=-mu[i];
else break;
}
}
}
int main(){
Sieve();
int n,m,ans=0; scanf("%d%d",&n,&m);
if(n>m) swap(n,m);
for(int i=1;i<=500000;i++) mi[i]=1;
for(int g=1,gg;g<=n;g++){
gg=Pow(g,g);
for(int i=1;i<=m/g;i++)
mi[i]=1ll*mi[i]*i%mod,smi[i]=(1ll*smi[i-1]+mi[i])%mod;
for(int d=1;d<=n/g;d++)
ans=(1ll*ans+1ll*mu[d]*mi[d]%mod*mi[d]%mod*smi[n/(g*d)]%mod*smi[m/(g*d)]%mod*gg%mod)%mod;
}
printf("%d",ans);
return 0;
}
●BZOJ 3561 DZY Loves Math VI的更多相关文章
- BZOJ 3561 DZY Loves Math VI
BZOJ 3561 DZY Loves Math VI 求\(\sum_{i=1}^{n}\sum_{j=1}^{m}\text{lcm}(i,j)^{\gcd(i,j)}\),钦定\(n\leq m ...
- BZOJ 3561: DZY Loves Math VI 莫比乌斯反演+复杂度分析
推到了一个推不下去的形式,然后就不会了 ~ 看题解后傻了:我推的是对的,推不下去是因为不需要再推了. 复杂度看似很大,但其实是均摊 $O(n)$ 的,看来分析复杂度也是一个能力啊 ~ code: #i ...
- 【BZOJ 3561】 3561: DZY Loves Math VI (莫比乌斯,均摊log)
3561: DZY Loves Math VI Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 205 Solved: 141 Description ...
- 【BZOJ】3561: DZY Loves Math VI
题意 求\(\sum_{i=1}^{n} \sum_{j=1}^{m} lcm(i, j)^{gcd(i, j)}\)(\(n, m<=500000\)) 分析 很显然要死推莫比乌斯 题解 设\ ...
- 【BZOJ3561】DZY Loves Math VI (数论)
[BZOJ3561]DZY Loves Math VI (数论) 题面 BZOJ 题解 \[\begin{aligned} ans&=\sum_{i=1}^n\sum_{j=1}^m\sum_ ...
- ●BZOJ 3309 DZY Loves Math
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3309 题解: 莫比乌斯反演,线筛 化一化式子: f(x)表示x的质因子分解中的最大幂指数 $ ...
- [BZOJ3561] DZY Loves Math VI
(14.10.28改) 本来只想写BZOJ3739:DZY Loves Math VIII的,不过因为和VI有关系,而且也没别人写过VI的题解,那么写下. 不过我还不会插公式…… http://www ...
- BZOJ 3309: DZY Loves Math
3309: DZY Loves Math Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 761 Solved: 401[Submit][Status ...
- BZOJ 3512: DZY Loves Math IV [杜教筛]
3512: DZY Loves Math IV 题意:求\(\sum_{i=1}^n \sum_{j=1}^m \varphi(ij)\),\(n \le 10^5, m \le 10^9\) n较小 ...
随机推荐
- Alpha第四天
Alpha第四天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...
- Beta冲刺随笔集合
Beta冲刺随笔集合 项目Beta预备 Beta冲刺第一天 Beta冲刺第二天 Beta冲刺第三天 Beta冲刺第四天 Beta冲刺第五天 Beta冲刺第六天 Beta冲刺第七天 用户调查报告 Bet ...
- 敏捷冲刺每日报告——Day4
1.情况简述 Alpha阶段第一次Scrum Meeting 敏捷开发起止时间 2017.10.28 00:00 -- 2017.10.29 00:00 讨论时间地点 2017.10.28晚9:30, ...
- 从0开始的LeetCode生活—001-Two Sum
题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...
- 过滤器Filter与监听器Listener
过滤器Filter 过滤器也是一种servlet 它也可以对用户的请求进行处理 , 但是他所做的处理,只是一些轻量级的处理.Fileter就好像jsp页面与servlet之间的一道关卡,如果这个 ...
- node创建第一个应用
如果我们使用PHP来编写后端的代码时,需要Apache 或者 Nginx 的HTTP 服务器,并配上 mod_php5 模块和php-cgi. 从这个角度看,整个"接收 HTTP 请求并提供 ...
- nyoj 概率计算
概率计算 时间限制:1000 ms | 内存限制:65535 KB 难度:1 描述 A和B两个人参加一场答题比赛.比赛的过程大概是A和B两个人轮流答题,A先答.一旦某人没有正确回答问题,则对手 ...
- js 点击 返回顶部 动画
附上效果图 触发前 触发后 HTML代码: CSS代码 JS代码 由于复制文本太丑了 所以直接放的图片 但是我在评论区把js代码又复制了一边 以便你们使用
- js进度条小事例
<style> #div1{width: 500px;height: 20px;border: 1px solid gray;} #div2{height: 20px;width: 0px ...
- maven 每次update后影响接口实现类的问题
遇到maven每次update后,就会更改eclipse中java Compiler中的jdk compliance版本 <plugin> <groupId>org.apach ...