P3327/bzoj3994 [SDOI2015]约数个数和(莫比乌斯反演)
2024-08-21 07:50:21
无话可补
#include<iostream>
#include<cstdio>
#include<cstring>
#define re register
using namespace std;
template<typename T>T max(T &a,T &b){return a>b?a:b;}
template<typename T>T min(T &a,T &b){return a<b?a:b;}
#define N 50001
int t,n,m,pct,pri[N],mu[N],sum[N];
long long g[N],ans;
bool v[N];
int main(){
mu[]=;
for(re int i=;i<N;++i){
if(!v[i]) pri[++pct]=i,mu[i]=-;
for(re int j=;j<=pct;++j){
re int tmp=i*pri[j];
if(tmp>=N) break;
v[tmp]=;
if(i%pri[j]) mu[tmp]=-mu[i];
else break;
}//线性筛
}re int u;
for(u=;u+<N;u+=){
sum[u]=sum[u-]+mu[u];
sum[u+]=sum[u]+mu[u+];
sum[u+]=sum[u+]+mu[u+];
sum[u+]=sum[u+]+mu[u+];
}//循环展开:微小加速
for(;u<N;++u) sum[u]=sum[u-]+mu[u];
for(re int i=;i<N;++i){
ans=;
for(re int l=,r;l<=i;l=r+){
r=i/(i/l);
ans+=1ll*(r-l+)*(i/l);
}g[i]=ans;
} scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
if(n>m) swap(n,m);
ans=;
for(re int l=,r;l<=n;l=r+){
r=min(n/(n/l),m/(m/l));
ans+=1ll*(sum[r]-sum[l-])*g[n/l]*g[m/l];
}printf("%lld\n",ans);
}return ;
}
最新文章
- R in Action 读书笔记(4)
- Mac OS 环境下 安装 Asp.Net及使用Yeoman 创建Asp.Net 项目
- 【转载】Pyqt QSplitter分割窗口
- Java 之 多线程编程
- GTD时间管理(3)---梳理总结
- android属性
- easyui中jquery重复引用问题(tab内存泄露问题)
- Django数据库配置
- linq to ef(相当于sql中in的用法)查询语句
- excel - 相等判断
- wxPython学习笔记(二)
- 阿里云服务器linux(centos)常用命令
- 脱掉Golang的第一层衣裳 golang入坑系列
- eclipse搭建maven ssm项目
- nginx上支持.htaccess伪静态的配置实例
- 如何优化 ThreadPoolExecutor
- Confluence 6 后台中的默认空间模板设置
- ASP.NET MVC布局
- Python3.X 安装Scrapy
- sklearn参数优化方法