P3327 [SDOI2015]约数个数和

神犇题解(转)

无话可补

#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 ;
}

最新文章

  1. R in Action 读书笔记(4)
  2. Mac OS 环境下 安装 Asp.Net及使用Yeoman 创建Asp.Net 项目
  3. 【转载】Pyqt QSplitter分割窗口
  4. Java 之 多线程编程
  5. GTD时间管理(3)---梳理总结
  6. android属性
  7. easyui中jquery重复引用问题(tab内存泄露问题)
  8. Django数据库配置
  9. linq to ef(相当于sql中in的用法)查询语句
  10. excel - 相等判断
  11. wxPython学习笔记(二)
  12. 阿里云服务器linux(centos)常用命令
  13. 脱掉Golang的第一层衣裳 golang入坑系列
  14. eclipse搭建maven ssm项目
  15. nginx上支持.htaccess伪静态的配置实例
  16. 如何优化 ThreadPoolExecutor
  17. Confluence 6 后台中的默认空间模板设置
  18. ASP.NET MVC布局
  19. Python3.X 安装Scrapy
  20. sklearn参数优化方法

热门文章

  1. timerWithTimeInterval 方法详用
  2. 安装安全狗后,MP4无法播放
  3. 【mysql】查看版本的四种方法
  4. 几种减小javascript对性能影响的方法
  5. shell出现syntax error near unexpected token `&lt;&#39; 解决方法
  6. IDEA Tomcat部署时war和war exploded区别以及平时踩得坑
  7. centos6.5安装sendmail
  8. 微信小程序 --- Image组件
  9. 【转载】细说 Form (表单)
  10. LayoutSimple简易响应式CSS布局框架