题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3994

推导过程和这里一样:https://www.cnblogs.com/MashiroSky/p/6365020.html

不用取模但注意开 long long 。

代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int const xn=5e4+;
int cnt,pri[xn];
ll f[xn],mu[xn];
bool vis[xn];
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return f?ret:-ret;
}
void init()
{
int mx=5e4; mu[]=;
for(int i=;i<=mx;i++)
{
if(!vis[i])pri[++cnt]=i,mu[i]=-;
for(int j=;j<=cnt&&(ll)i*pri[j]<=mx;j++)
{
vis[i*pri[j]]=;
if(i%pri[j])mu[i*pri[j]]=-mu[i];
else break;
}
}
for(int i=;i<=mx;i++)mu[i]+=mu[i-];
for(int n=;n<=mx;n++)
for(int i=,j;i<=n;i=j+)
{
j=n/(n/i);
f[n]+=(ll)(n/i)*(j-i+);//
}
}
int main()
{
int T=rd(); init();
while(T--)
{
int n=rd(),m=rd(); int mn=min(n,m); ll ans=;//
for(int i=,j;i<=mn;i=j+)
{
j=min(n/(n/i),m/(m/i));
ans+=(mu[j]-mu[i-])*f[n/i]*f[m/i];
}
printf("%lld\n",ans);
}
return ;
}

bzoj 3994 约数个数和 —— 反演+数论分块的更多相关文章

  1. BZOJ 3994 约数个数和

    Description 设\(d(x)\)为\(x\)的约数个数,给定\(N,M\),求\[\sum_{i=1}^{N}\sum_{j=1}^{M}d(ij)\]. Input 输入文件包含多组测试数 ...

  2. [BZOJ 2154]Crash的数字表格(莫比乌斯反演+数论分块)

    [BZOJ 2154]Crash的数字表格(莫比乌斯反演+数论分块) 题面 求 \[\sum_{i=1}^{n} \sum_{j=1}^{m} \mathrm{lcm}(i,j)\] 分析 \[\su ...

  3. [BZOJ 2820] YY的gcd(莫比乌斯反演+数论分块)

    [BZOJ 2820] YY的gcd(莫比乌斯反演+数论分块) 题面 给定N, M,求\(1\leq x\leq N, 1\leq y\leq M\)且gcd(x, y)为质数的(x, y)有多少对. ...

  4. [BZOI 3994] [SDOI2015]约数个数和(莫比乌斯反演+数论分块)

    [BZOI 3994] [SDOI2015]约数个数和 题面 设d(x)为x的约数个数,给定N.M,求\(\sum _{i=1}^n \sum_{i=1}^m d(i \times j)\) T组询问 ...

  5. bzoj 3994 [SDOI2015]约数个数和——反演

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3994 \( d(i*j)=\sum\limits_{x|i}\sum\limits_{y|j ...

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

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

  7. 【BZOJ2820】YY的GCD(莫比乌斯反演 数论分块)

    题目链接 大意 给定多组\(N\),\(M\),求\(1\le x\le N,1\le y\le M\)并且\(Gcd(x, y)\)为质数的\((x, y)\)有多少对. 思路 我们设\(f(i)\ ...

  8. BZOJ 2956 模积和 (数学推导+数论分块)

    手动博客搬家: 本文发表于20170223 16:47:26, 原地址https://blog.csdn.net/suncongbo/article/details/79354835 题目链接: ht ...

  9. BZOJ2301/LG2522 「HAOI2011」Problem B 莫比乌斯反演 数论分块

    问题描述 BZOJ2301 LG2522 积性函数 若函数 \(f(x)\) 满足对于任意两个最大公约数为 \(1\) 的数 \(m,n\) ,有 \(f(mn)=f(m) \times f(n)\) ...

随机推荐

  1. React-Native在gitHub下载的Demo不能运行问题!!!

    1.目前找到的最可行的运行React-Native Demo的解决方案 请参考:http://blog.csdn.net/shubinniu/article/details/52873250 2.检查 ...

  2. 11.23 Eclipse

    一.Eclipse Workspace File-->Switch Workspace 编译环境:Window -- Preferences – Java - Compiler 运行环境:Win ...

  3. Floyd 学习笔记

    #include <cstdio> #include <cstring> #include <ctype.h> #include <cstdlib> # ...

  4. UI组件之Label

    Use Core Data 接口,链接数据库 Portrait 肖像模式 LandScape(Left, Right) 风景模式 1.程序启动后,从main接口进入, main函数会调用UIAppli ...

  5. 《程序员代码面试指南》第一章 栈和队列 构造数组的MaxTree

    题目 给出一个无重复元素的数组,构造此数组的MaxTree, java代码 /** * @Description: 构造数组的MaxTree * @Author: lizhouwei * @Creat ...

  6. Python 3 mysql 表操作

    Python 3 mysql 表操作 表相当于文件,表中的一条记录就相当于文件的一行内容,不同的是,表中的一条记录有对应的标题,称为表的字段 id,name,qq,age称为字段,其余的,一行内容称为 ...

  7. python3 包

    python3 包 执行文件为test.py,内容 #test.py import aaa 同级目录下创建目录aaa,然后自建空__init__.py(或者干脆建包) 需求:验证导入包就是在导入包下的 ...

  8. 95th percentile concentration

    很多网络流量监控软件都提供了一个95th的值,开始一直不太理解,终于在solarwinds官网找到答案. 95th百分点指的是所给数集中超过其95%的数.它是一个统计学上的概念.对于某个接口,准确统计 ...

  9. java入门了解之快捷键

    IDE(Integrated Development Environment ): 集成开发环境,集合开发.运行.调试于一体的一个软件 Eclipse 是一个开放源代码的.基于Java的可扩展开发平台 ...

  10. logstash的output插件

    logstash 的output插件 nginx,logstash和redis在同一台机子上 yum -y install redis,vim /etc/redis.conf 设置bind 0.0.0 ...