\(x=p_1^{\alpha_1}p_2^{\alpha_2}...p_c^{\alpha_c}\)

\(f(x)=\max(\alpha_1,\alpha_2,...,\alpha_c)\)

\(assume\ n\leq m\)

\(\sum_{i=1}^{n}\sum_{j=1}^{m}f(\gcd(i,j))\)

\(\sum_{x=1}^{n}f(x)\sum_{i=1}^{n}\sum_{j=1}^{m}[\gcd(i,j)=x]\)

\(\sum_{x=1}^{n}f(x)\sum_{i=1}^{\frac nx}\sum_{j=1}^{\frac mx}[\gcd(i,j)=1]\)

\(\sum_{x=1}^{n}f(x)\sum_{d=1}^{\frac nx}\mu(d)\sum_{i=1}^{\frac nx}\sum_{j=1}^{\frac mx}[d|i,d|j]\)

\(\sum_{x=1}^{n}f(x)\sum_{d=1}^{\frac nx}\mu(d)\lfloor \frac {n}{dx}\rfloor\lfloor \frac {m}{dx}\rfloor\)

\(\sum_{x=1}^{n}f(x)\sum_{x|d}\mu(\frac dx)\lfloor \frac {n}{d}\rfloor\lfloor \frac {m}{d}\rfloor\)

\(\sum_{d=1}^{n}\lfloor \frac {n}{d}\rfloor\lfloor \frac {m}{d}\rfloor\sum_{x|d}f(x)\mu(\frac dx)\)

根据套路,我们到了这个式子。直接暴力调和级数算 \(\sum_{x|d}f(x)\mu(\frac dx)\) 的前缀和,时间复杂度 \(O(n\log n)\)

怎么 \(O(n)\) 筛的锅待填

\(O(n\log n):\)

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=10000000+10;
int n,m,f[maxn],mu[maxn],prim[maxn],vis[maxn],cnt;
ll g[maxn]; inline int read(){
register int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return (f==1)?x:-x;
} void pre(int n){
mu[1]=1;
for(int i=2;i<=n;i++){
if(!vis[i]){prim[++cnt]=i;mu[i]=-1;}
for(int j=1;i*prim[j]<=n&&j<=cnt;j++){
vis[i*prim[j]]=1;
if(i%prim[j]==0) break;
mu[i*prim[j]]=-mu[i];
}
}
int num,ans;
for(int i=1;i<=cnt;i++){
for(int j=prim[i];j<=n;j+=prim[i]){
num=j;ans=0;
while(num%prim[i]==0) num/=prim[i],ans++;
f[j]=max(f[j],ans);
}
}
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j+=i) g[j]+=f[i]*mu[j/i];
for(int i=1;i<=n;i++) g[i]+=g[i-1];
} int main()
{
pre(10000000);
int T=read();
while(T--){
n=read(),m=read();
if(n>m) swap(n,m);
ll ans=0;
for(int l=1,r;l<=n;l=r+1){
r=min(n/(n/l),m/(m/l));
ans+=(ll)(n/l)*(m/l)*(g[r]-g[l-1]);
}
printf("%lld\n",ans);
}
return 0;
}

\(O(n):\)

#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
const int maxn=10000000+10;
int n,m,f[maxn],low[maxn],prim[maxn],vis[maxn],cnt;
ll g[maxn]; inline int read(){
register int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return (f==1)?x:-x;
} void pre(int n){
for(int i=2;i<=n;i++){
if(!vis[i]){low[i]=prim[++cnt]=i;f[i]=g[i]=1;}
for(int j=1;i*prim[j]<=n&&j<=cnt;j++){
vis[i*prim[j]]=1;
if(i%prim[j]==0){
f[i*prim[j]]=f[i]+1;low[i*prim[j]]=low[i]*prim[j];
if(i==low[i]) g[i*prim[j]]=1;
else g[i*prim[j]]=(f[i/low[i]]==f[i*prim[j]])?-g[i/low[i]]:0;
break;
}
f[i*prim[j]]=1;low[i*prim[j]]=prim[j];
g[i*prim[j]]=(f[i]==1)?-g[i]:0;
}
}
for(int i=1;i<=n;i++) g[i]+=g[i-1];
} signed main()
{
pre(10000000);
int T=read();
while(T--){
n=read(),m=read();
if(n>m) swap(n,m);
ll ans=0;
for(int l=1,r;l<=n;l=r+1){
r=min(n/(n/l),m/(m/l));
ans+=(ll)(n/l)*(m/l)*(g[r]-g[l-1]);
}
printf("%lld\n",ans);
}
return 0;
}

DZY Loves Math(莫比乌斯反演)的更多相关文章

  1. 【BZOJ】3309: DZY Loves Math 莫比乌斯反演优化

    3309: DZY Loves Math Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007) ...

  2. bzoj 3309 DZY Loves Math 莫比乌斯反演

    DZY Loves Math Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1303  Solved: 819[Submit][Status][Dis ...

  3. 【BZOJ3309】DZY Loves Math 莫比乌斯反演+线性筛(好题)

    [BZOJ3309]DZY Loves Math Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10 ...

  4. 【BZOJ3309】DZY Loves Math - 莫比乌斯反演

    题意: 对于正整数n,定义$f(n)$为$n$所含质因子的最大幂指数.例如$f(1960)=f(2^3 * 5^1 * 7^2)=3$,$f(10007)=1$,$f(1)=0$. 给定正整数$a,b ...

  5. 【bzoj3309】DZY Loves Math 莫比乌斯反演+线性筛

    Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007)=1, f(1)=0. 给定正整数a,b, ...

  6. BZOJ 3309 DZY Loves Math ——莫比乌斯反演

    枚举$d=gcd(i,j)$ 然后大力反演 ——来自Popoqqq的博客. 然后大力讨论后面的函数的意义即可. http://blog.csdn.net/popoqqq/article/details ...

  7. BZOJ 3309: DZY Loves Math [莫比乌斯反演 线性筛]

    题意:\(f(n)\)为n的质因子分解中的最大幂指数,求\(\sum_{i=1}^n \sum_{j=1}^m f(gcd(i,j))\) 套路推♂倒 \[ \sum_{D=1}^n \sum_{d| ...

  8. [BZOJ3309]DZY Loves Math(莫比乌斯反演+线性筛)

    $\sum\limits_{T=1}^{n}\lfloor\frac{n}{T}\rfloor\lfloor\frac{m}{T}\rfloor\sum\limits_{d|T}f(d)\mu(\fr ...

  9. bzoj 3309 DZY Loves Math —— 莫比乌斯反演+数论分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3309 凭着上课所讲和与 Narh 讨论推出式子来: 竟然是第一次写数论分块!所以迷惑了半天: ...

  10. BZOJ 3309: DZY Loves Math 莫比乌斯反演+打表

    有一个神奇的技巧——打表 code: #include <bits/stdc++.h> #define N 10000007 #define ll long long #define se ...

随机推荐

  1. OpenSSH配置与基本使用

    SSH访问远程 SSH常见分类: telnet-远程登录协议,23/TCP 明文认证.明文传输(不安全) ssh(Secure SHell)-应用层协议,22/TCP 通讯和认证过程加密.主机认证 用 ...

  2. 【转载】 了解实时媒体的播放(RTP/RTCP 和 RTSP)

    http://blog.csdn.net/span76/article/details/12913307 离线媒体只是用 Http协议去读取服务器端文件而已,而对于实时直播如何实现, 这里就要用到 R ...

  3. syslog系统日志、事件日志分析、EventLog Analyzer

    syslog系统日志.事件日志分析.EventLog Analyzer Eventlog Analyzer是用来分析和审计系统及事件日志的管理软件,能够对全网范围内的主机.服务器.网络设备.数据库以及 ...

  4. windows下解决端口被占用的问题

    步骤一.Windows查看所有的端口 点击电脑左下角的开始,然后选择运行选项,接着我们在弹出的窗口中,输入[cmd]命令,进行命令提示符.然后我们在窗口中输入[netstat -ano]按下回车,即会 ...

  5. oracle在exp导出时报错PLS-00201: identifier 'EXFSYS.DBMS_EXPFIL_DEPASEXP' must be declared

    报错如下信息: EXP-00008: ORACLE error 6550 encounteredORA-06550: line 1, column 14:PLS-00201: identifier ' ...

  6. Attach()和Detach()函数

    一.Windows对象和MFC对象的区别? MFC对象实际上并没有把整个Windows对象都包装在其中.对于窗口:MFC对象它只是有一个窗口句柄而已,这个窗口句柄如果指向一个实际存在的窗口对象(窗口对 ...

  7. Docker Compose部署lnmp

    参考:https://github.com/micooz/docker-lnmp 一.简介 使用Dcoekr镜像部署lnmp(Linux.Nginx.MySQL.PHP7). 1.1 结构 app └ ...

  8. bat文件命令

  9. 20169207《Linux内核原理与分析》第九周作业

    第九周的实验依旧和往常的一样,主要包括两部分.一是1.阅读学习教材「Linux内核设计与实现 (Linux Kernel Development)」第教材第13,14章.二是学习MOOC「Linux内 ...

  10. CentOS FTP服务器系统套件全面讲解

    对大家推荐很好使用的CentOS FTP系统,像让大家对CentOS FTP系统有所了解,然后对CentOS FTP系统全面讲解介绍,希望对大家有用. 1.vsFTPd,目前常用CentOS FTP服 ...