【题解】Zap(莫比乌斯反演)
【题解】Zap(莫比乌斯反演)
裸题...
直接化吧
[P3455 POI2007]ZAP-Queries
所有除法默认向下取整
\\
=\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(莫比乌斯反演)的更多相关文章
- BZOJ1101: [POI2007]Zap(莫比乌斯反演)
1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2951 Solved: 1293[Submit][Status ...
- Bzoj1101: [POI2007]Zap 莫比乌斯反演+整除分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 莫比乌斯反演 1101: [POI2007]Zap 设 \(f(i)\) 表示 \(( ...
- 【BZOJ1101】Zap [莫比乌斯反演]
Zap Time Limit: 10 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 对于给定的整数a,b和d,有多少正整 ...
- 1101: [POI2007]Zap(莫比乌斯反演)
1101: [POI2007]Zap Time Limit: 10 Sec Memory Limit: 162 MB Description FGD正在破解一段密码,他需要回答很多类似的问题:对于给定 ...
- bzoj 1101 Zap —— 莫比乌斯反演
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1101 直接莫比乌斯反演. 代码如下: #include<cstdio> #inc ...
- BZOJ 1101 Luogu P3455 POI 2007 Zap (莫比乌斯反演+数论分块)
手动博客搬家: 本文发表于20171216 13:34:20, 原地址https://blog.csdn.net/suncongbo/article/details/78819470 URL: (Lu ...
- CF1139D Steps to One 题解【莫比乌斯反演】【枚举】【DP】
反演套 DP 的好题(不用反演貌似也能做 Description Vivek initially has an empty array \(a\) and some integer constant ...
- BZOJ 1101: [POI2007]Zap( 莫比乌斯反演 )
求 answer = ∑ [gcd(x, y) = d] (1 <= x <= a, 1 <= y <= b) . 令a' = a / d, b' = b / d, 化简一下得 ...
- BZOJ 1101 Zap(莫比乌斯反演)
http://www.lydsy.com/JudgeOnline/problem.php?id=1101 给定a,b,d,求有多少gcd(x,y)==d(1<=x<=a&& ...
随机推荐
- LeetCode 66 Plus One(加一)(vector)
翻译 给定一个以一系列数字表示的非负数.将其加一并转换成数字. 数字存储的最高位在列的最前面. 原文 Given a non-negative number represented as an arr ...
- cordova开发自己定义插件
以下是自己定义cordova插件的基本入门.做插件的小白可以參考一下哈,兴许会更新插件的进阶博客,希望大家可以共同学习共同进步 1.环境搭建 cordova插件开发前须要安装一些软件和配置环境 1.1 ...
- LeetCode之小孩分糖果
给定一群站好队的小孩而且按某项分值排名(姑且如果为年龄吧),年龄大的要比他身边年龄小的拿的糖要多.求怎么分配糖果使得分配的糖果数最少. 用一个数组从左到右再从右到左的遍历,向前遍历时若右边的比左边的大 ...
- 测试xxxxxxxx
测试sdfs xxxxxxxbgssdfsdf f sd=JS-demp.zip f /** * @author John Smith <john.smith@example.com> ...
- Enum,int,string类型互转
举例:enum Colors { Red, Green, Blue, Yellow }; Enum-->String (1)利用Object.ToString()方法:如Colors.Green ...
- Delphi获得与设置系统时间格式《转》
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Syst ...
- JAVA方法传递参数:传值?传引用?
先来看下面这三段代码: //Example1: public class Example1 { static void check(int a) { a++; } public static void ...
- QT错误笔记-Qt Creator needs a compiler set up to build. Configure a compiler in the kit options.
上午在linux环境下,使用QT编译一段C++代码,出现下列错误: 最近在stackoverflow上找到了答案: i was also having the same problem so what ...
- Servlet3.0: 简介AsyncContext
每个请求来到Web容器,Web容器会为其分配一条执行绪来专门负责该请求,直到回应完成前,该执行绪都不会被释放回容器. 执行绪会耗用系统资源,若有些请求需要长时间处理(例如长时间运算.等待某个资源),就 ...
- FastMethod和PropertyUtils两种反射方法的性能比较
这两个类都提供反射方法的实现,性能对比如下: 循环条件是:1亿次 结论:PropertyUtils提供的getXXX和setXXX反射方法的性能是FastMethod的三倍 以下是测试方法: 首先是F ...