bzoj 3994 约数个数和 —— 反演+数论分块
题目: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 约数个数和 —— 反演+数论分块的更多相关文章
- BZOJ 3994 约数个数和
Description 设\(d(x)\)为\(x\)的约数个数,给定\(N,M\),求\[\sum_{i=1}^{N}\sum_{j=1}^{M}d(ij)\]. Input 输入文件包含多组测试数 ...
- [BZOJ 2154]Crash的数字表格(莫比乌斯反演+数论分块)
[BZOJ 2154]Crash的数字表格(莫比乌斯反演+数论分块) 题面 求 \[\sum_{i=1}^{n} \sum_{j=1}^{m} \mathrm{lcm}(i,j)\] 分析 \[\su ...
- [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)有多少对. ...
- [BZOI 3994] [SDOI2015]约数个数和(莫比乌斯反演+数论分块)
[BZOI 3994] [SDOI2015]约数个数和 题面 设d(x)为x的约数个数,给定N.M,求\(\sum _{i=1}^n \sum_{i=1}^m d(i \times j)\) T组询问 ...
- bzoj 3994 [SDOI2015]约数个数和——反演
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3994 \( d(i*j)=\sum\limits_{x|i}\sum\limits_{y|j ...
- bzoj 3309 DZY Loves Math —— 莫比乌斯反演+数论分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3309 凭着上课所讲和与 Narh 讨论推出式子来: 竟然是第一次写数论分块!所以迷惑了半天: ...
- 【BZOJ2820】YY的GCD(莫比乌斯反演 数论分块)
题目链接 大意 给定多组\(N\),\(M\),求\(1\le x\le N,1\le y\le M\)并且\(Gcd(x, y)\)为质数的\((x, y)\)有多少对. 思路 我们设\(f(i)\ ...
- BZOJ 2956 模积和 (数学推导+数论分块)
手动博客搬家: 本文发表于20170223 16:47:26, 原地址https://blog.csdn.net/suncongbo/article/details/79354835 题目链接: ht ...
- BZOJ2301/LG2522 「HAOI2011」Problem B 莫比乌斯反演 数论分块
问题描述 BZOJ2301 LG2522 积性函数 若函数 \(f(x)\) 满足对于任意两个最大公约数为 \(1\) 的数 \(m,n\) ,有 \(f(mn)=f(m) \times f(n)\) ...
随机推荐
- Gone Fishing(贪心)
Gone Fishing John is going on a fising trip. He has h hours available (1 ≤ h ≤ 16), and there are n ...
- shu7-19【背包和母函数练习】
题目:http://acm.hdu.edu.cn/diy/contest_show.php?cid=20083 密码:shuacm 感觉他们学校的新生训练出的比较好. 今天很多题目都是强化了背包的转化 ...
- The given 'driver' ] is unknown, Doctrine currently supports only the follo wing drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo
[Doctrine\DBAL\DBALException] The given 'driver' ] ...
- Excel 文件下载
INCLUDE OLE2INCL * ALV输出 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PRO ...
- 运用starling开发的手游FlappyBird
最近想向游戏方面发展,于是用starling做了一个简易版的FlappyBird,纯AS3开发,权当是技术学习.在发布之后才明白要发布一个没有版权的app是有多困难,审核了N遍之后终于通过审核,下面发 ...
- 高性能javascript学习总结(2)--DOM编程
我们知道,对DOM的操作都是非常的耗性能的,那么为什么会耗性能呢? 文档对象模型(DOM)是一个独立于语言的,使用 XML和 HTML 文档操作的应用程序接口(API).在浏览器中,主要与 ...
- static_new
<?php //在::操作符的左边写上类的名称来静态地访问某个成员,这样就可以避免创建类的实例. //这样不仅可以省略掉实例化类的代码,而且还会更高效,因为类的每个实例都会占用一小部分的系统资源 ...
- VHDL学习笔记——数字系统设计
数字系统是指有若干数字电路和逻辑不见构成的能够处理或传输数字信息的设备.数字系统可分为三部分:输入输出接口.数据处理器和控制器. [传统的系统硬件设计]方法是(1)采用自底向上的设计方法(2)采用通用 ...
- Data Structure Binary Tree: Largest Independent Set Problem
http://www.geeksforgeeks.org/largest-independent-set-problem/ #include <iostream> #include < ...
- css 分析
.important.warning {background:silver;} .important .warning {background:silver;} //上面有什么区别? //1.2个选择 ...