【题解】Zap(莫比乌斯反演)

裸题...

直接化吧

[P3455 POI2007]ZAP-Queries

所有除法默认向下取整

\[\Sigma_{i=1}^x\Sigma_{j=1}^y[(i,j)=k]
\\
=\Sigma_{i=1}^{x/k}\Sigma_{j=1}^{y/k}[(i,j)=1]
\\
=\Sigma_{i=1}^{x/k}\Sigma_{j=1}^{y/k}\Sigma_{d|(i,j)}\mu(d)
\\
=\Sigma_{d=1}^{min(x,y)}\Sigma_{i=1}^{x/k}\Sigma_{j=1}^{y/k}\mu(d)\times[d|(i,j)]
\\
=\Sigma_{d=1}^{min(x,y)}(\frac x {dk})(\frac y {dk})\mu(d)
\]

整除分块直接做...

有一个细节,可能有疑惑:

		r=min(x/(x/l),y/(y/l));
ans+=1ll*(x/(l*k))*(y/((l*k)))*(sum[r]-sum[l-1]);

整除分块为什么是这样的?为什么r=min(x/(x/l),y/(y/l));中的"\(l\)"和ans+=1ll*(x/(l*k))*(y/((l*k)))*(sum[r]-sum[l-1]);不统一,为什么是(x/(l*k))*(y/(l*k))?这不是整除分块正常的套路啊?

可以这样理解,整除分块利用了\(\lfloor \frac x l \rfloor\)在一定范围内不变的性质,所以我们同样也会有\(\lfloor\frac {\lfloor \frac x l \rfloor} k\rfloor\)在一定范围内不变化,并且前面那个式子包括的\(l\)的范围一定小于后面的那个\(l\)的范围,所以我们按照\(\lfloor \frac x l \rfloor\)整除分块即可。

至于如何按照\(\lfloor\frac {\lfloor \frac x l \rfloor} k\rfloor=\lfloor \frac x {lk} \rfloor\)分块,我也不知道怎么办,希望有高手指点一下QAQ

#include<bits/stdc++.h>

using namespace std;typedef long long ll;
template < class ccf >
inline ccf qr(ccf b){
register char c=getchar();register int q=1;register ccf x=0;
while(c<48||c>57)q=c==45?-1:q,c=getchar();
while(c>=48&&c<=57)x=x*10+c-48,c=getchar();
return q==-1?-x:x;}
inline int qr(){return qr(1);}
const int maxn=1e5+5;
bool usd[maxn];
int mu[maxn];
int sum[maxn];
vector < int > ve;
int x,y,k;
#define pb push_back
inline void gen(){
mu[1]=sum[1]=usd[1]=1;
for(register int t=2;t< maxn;++t){
if(not usd[t])
ve.pb(t),mu[t]=-1;
for(register auto p:ve)
if(1ll*p*t<maxn)
if(usd[p*t]=1,t%p) mu[p*t]=-mu[t];
else break;
else break;
sum[t]=sum[t-1]+mu[t];
}
} int main(){
gen();
int T=qr();
while(T--){
x=qr();y=qr();k=qr();
ll ans=0;
for(register int l=1,r=0,edd=min(x,y)/k;l<=edd;l=r+1){
r=min(x/(x/l),y/(y/l));
ans+=1ll*(x/(l*k))*(y/((l*k)))*(sum[r]-sum[l-1]);
}
cout<<ans<<endl;
}
return 0;
}

【题解】Zap(莫比乌斯反演)的更多相关文章

  1. BZOJ1101: [POI2007]Zap(莫比乌斯反演)

    1101: [POI2007]Zap Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2951  Solved: 1293[Submit][Status ...

  2. Bzoj1101: [POI2007]Zap 莫比乌斯反演+整除分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 莫比乌斯反演 1101: [POI2007]Zap 设 \(f(i)\) 表示 \(( ...

  3. 【BZOJ1101】Zap [莫比乌斯反演]

    Zap Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description 对于给定的整数a,b和d,有多少正整 ...

  4. 1101: [POI2007]Zap(莫比乌斯反演)

    1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定 ...

  5. bzoj 1101 Zap —— 莫比乌斯反演

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 直接莫比乌斯反演. 代码如下: #include<cstdio> #inc ...

  6. BZOJ 1101 Luogu P3455 POI 2007 Zap (莫比乌斯反演+数论分块)

    手动博客搬家: 本文发表于20171216 13:34:20, 原地址https://blog.csdn.net/suncongbo/article/details/78819470 URL: (Lu ...

  7. CF1139D Steps to One 题解【莫比乌斯反演】【枚举】【DP】

    反演套 DP 的好题(不用反演貌似也能做 Description Vivek initially has an empty array \(a\) and some integer constant ...

  8. BZOJ 1101: [POI2007]Zap( 莫比乌斯反演 )

    求 answer = ∑ [gcd(x, y) = d] (1 <= x <= a, 1 <= y <= b) . 令a' = a / d, b' = b / d, 化简一下得 ...

  9. BZOJ 1101 Zap(莫比乌斯反演)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1101 给定a,b,d,求有多少gcd(x,y)==d(1<=x<=a&& ...

随机推荐

  1. 常用sql语句记录

    1.表 --建表 if OBJECT_ID('Student') is not null create table Student( ID ,) not null, Name ), Code ), f ...

  2. opencv的C语言接口和C++接口差别(入门篇)

    opencv是一个开源的图像处理库,最经典的1.0版本号提供的接口都是C语言接口. 后来的opencv2.x版本号保留了C语言接口,可是提供了C++接口,当中的C语言接口仅仅是为了向后兼容,而C++接 ...

  3. netty的理解

    netty作为nio应用的典范,在很多设计方面都值得我们在程序开发中学习. 1.事件驱动,三种事件的传播机制.一种是在channel上触发,一种是在pipeline上触发,一种是在context上触发 ...

  4. 170. Two Sum III - Data structure design【easy】

    170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should suppor ...

  5. deepin linux下python安装mysqldb

    ` sudo pip search MySQL-python `

  6. Ubuntu安装Sun JDK

    Ubuntu 14.04 下安装 Sun JDK 1.8.0 1.下载JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk8- ...

  7. Codeforces 460E Roland and Rose(暴力)

    题目链接:Codeforces 460E Roland and Rose 题目大意:在以原点为圆心,半径为R的局域内选择N个整数点,使得N个点中两两距离的平方和最大. 解题思路:R最大为30.那么事实 ...

  8. lcd中像素深度bpp和像素格式(比如RGB,YUV)的关系

    像素深度(bits per pixel,简称bpp) 一个像素的颜色在计算机中由多少个字节数据来描述.计算机中用二进制位来表示一个像素的数据,用来表示一个像素的数据位越多,则这个像素的颜色值更加丰富. ...

  9. LeetCode207. Course Schedule

    Description There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses m ...

  10. eclipse 打开的时候弹出 'Building workspace' has encountered a problem. Errors occurred during

    Eclipse 里面project->Build Automatically上的对勾去掉