https://www.luogu.org/problemnew/show/P3455

就是https://www.cnblogs.com/hehe54321/p/9315244.html里面的方法2了,升级版的整除分块,可以两个变量一起搞

预处理莫比乌斯函数的前缀和之后就可以每次$O(\sqrt{n}+\sqrt{m})$回答

那篇题解里面用了一个技巧:${\lfloor}\frac{{\lfloor}\frac{a}{b}{\rfloor}}{c}{\rfloor}={\lfloor}\frac{a}{bc}{\rfloor}$

(当然a,b,c都为正整数)

证了好久。。。

这么证:

设${\lfloor}\frac{a}{bc}{\rfloor}=p$,则p为整数,且$p<=\frac{a}{bc}<p+1$

则$pc<=\frac{a}{b}<pc+c$

而$pc$与$pc+c$都为整数

因此$pc<={\lfloor}\frac{a}{b}{\rfloor}<pc+c$

所以$p<=\frac{{\lfloor}\frac{a}{b}{\rfloor}}{c}<p+1$

所以${\lfloor}\frac{{\lfloor}\frac{a}{b}{\rfloor}}{c}{\rfloor}=p={\lfloor}\frac{a}{bc}{\rfloor}$

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define N 50100
ll prime[N+],len,mu[N+],dd[N+];
bool nprime[N+];
ll a,c,n,m,k,ans,ed;
int main()
{
ll i,j,T,TT;
mu[]=;
for(i=;i<=N;i++)
{
if(!nprime[i]) prime[++len]=i,mu[i]=-;
for(j=;j<=len&&i*prime[j]<=N;j++)
{
nprime[i*prime[j]]=;
if(i%prime[j]==) {mu[i*prime[j]]=;break;}
else mu[i*prime[j]]=-mu[i];
}
}
for(i=;i<=N;i++) dd[i]=dd[i-]+mu[i];
scanf("%lld",&T);
for(TT=;TT<=T;TT++)
{
scanf("%lld%lld%lld",&n,&m,&k);n/=k;m/=k;
ans=;
if(n>m) swap(n,m);
for(i=;i<=n;i=j+)
{
j=min(n,min(n/(n/i),m/(m/i)));
ans+=(dd[j]-dd[i-])*(n/i)*(m/i);
}
printf("%lld\n",ans);
}
return ;
}

https://www.luogu.org/problemnew/show/P2522

https://www.lydsy.com/JudgeOnline/problem.php?id=2301

这题基本一样的,就是加个容斥。。

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define N 50100
ll prime[N+],len,mu[N+],dd[N+];
bool nprime[N+];
ll a,c,n,m,k;
ll calc(ll n,ll m)
{
if(n==||m==) return ;
ll ans=;
if(n>m) swap(n,m);
n/=k;m/=k;
for(ll i=,j;i<=n;i=j+)
{
j=min(n,min(n/(n/i),m/(m/i)));
ans+=(dd[j]-dd[i-])*(n/i)*(m/i);
}
return ans;
}
int main()
{
ll i,j,T,TT;
mu[]=;
for(i=;i<=N;i++)
{
if(!nprime[i]) prime[++len]=i,mu[i]=-;
for(j=;j<=len&&i*prime[j]<=N;j++)
{
nprime[i*prime[j]]=;
if(i%prime[j]==) {mu[i*prime[j]]=;break;}
else mu[i*prime[j]]=-mu[i];
}
}
for(i=;i<=N;i++) dd[i]=dd[i-]+mu[i];
scanf("%lld",&T);
for(TT=;TT<=T;TT++)
{
scanf("%lld%lld%lld%lld%lld",&a,&n,&c,&m,&k);
printf("%lld\n",calc(n,m)-calc(a-,m)-calc(n,c-)+calc(a-,c-));
}
return ;
}

洛谷 P3455 [POI2007]ZAP-Queries || 洛谷P2522,bzoj2301的更多相关文章

  1. 莫比乌斯反演学习笔记+[POI2007]Zap(洛谷P3455,BZOJ1101)

    先看一道例题:[POI2007]Zap BZOJ 洛谷 题目大意:$T$ 组数据,求 $\sum^n_{i=1}\sum^m_{j=1}[gcd(i,j)=k]$ $1\leq T\leq 50000 ...

  2. 洛谷 P3455 [POI2007]ZAP-Queries (莫比乌斯函数)

    题目链接:P3455 [POI2007]ZAP-Queries 题意 给定 \(a,b,d\),求 \(\sum_{x=1}^{a} \sum_{y=1}^{b}[gcd(x, y) = d]\). ...

  3. 【刷题】洛谷 P3455 [POI2007]ZAP-Queries

    题目描述 Byteasar the Cryptographer works on breaking the code of BSA (Byteotian Security Agency). He ha ...

  4. 洛谷P3455 [POI2007]ZAP-Queries(莫比乌斯反演)

    传送门 设$$f(k)=\sum_{i=1}^{a}\sum_{j=1}^{b}[gcd(i,j)=k]$$ $$g(n)=\sum_{n|k}f(k)=\lfloor\frac{a}{n}\rflo ...

  5. 洛谷P3455 [POI2007]ZAP-Queries

    题目大意: 给定\(n,m,k,\) 求 \[\sum\limits_{x=1}^n\sum\limits_{y=1}^m[gcd(x,y)==k]\] 莫比乌斯反演入门题,先进行一步转化,将每个\( ...

  6. 洛谷P3455 [POI2007]ZAP-Queries (莫比乌斯反演)

    题意:求$\sum_{i=1}^{a}\sum_{j=1}^{b}[gcd(i,j)==d]$(1<=a,b,d<=50000). 很套路的莫比乌斯反演. $\sum_{i=1}^{n}\ ...

  7. [Luogu P3455] [POI2007]ZAP-Queries (莫比乌斯反演 )

    题面 传送门:洛咕 Solution 这题比这题不懂简单到哪里去了 好吧,我们来颓柿子. 为了防止重名,以下所有柿子中的\(x\)既是题目中的\(d\) 为了方便讨论,以下柿子均假设\(b>=a ...

  8. BZOJ 1101: [POI2007]Zap

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

  9. [BZOJ1101][POI2007]Zap

    [BZOJ1101][POI2007]Zap 试题描述 FGD正在破解一段密码,他需要回答很多类似的问题:对于给定的整数a,b和d,有多少正整数对x,y,满足x<=a,y<=b,并且gcd ...

随机推荐

  1. Linux input子系统实例分析(二)

    紧接着上一节的实例我们来分析调用的input子系统的接口: 1. input_dev,用来标识输入设备 1: struct input_dev { 2: const char *name; //设备名 ...

  2. 【bzoj4653】[Noi2016]区间

    离散化+线段树 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstri ...

  3. Delphi如何实现多国语言

    Delphi里的多语言处理方法都一样, 都是通过资源DLL的形式进行加载处理. Delphi在加载form数据的时候会判断当前的系统语言,然后根据语言加载不同的资源dll, 来实现多国语言的功能. 下 ...

  4. JS中prototype,js原型扩展

    作者:轩脉刃(yjf512)出处:(http://www.cnblogs.com/yjf512/)版权声明:本文的版权归作者与博客园共有.欢迎转载阅读,转载时须注明本文的详细链接. 原文 http:/ ...

  5. SVN地址正确,能在网页打开,但是检出失败解决方法

    TortoiseSVN缓存问题 右键点击TortoiseSVN -> Settings -> Saved Data, 点击个个“Clear”按钮,把本地缓存都清除了,点击“确定”: 再重新 ...

  6. HDU 5687 Problem C

    Problem C Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  7. 数据结构之 栈与队列--- 走迷宫(深度搜索dfs)

    走迷宫 Time Limit: 1000MS Memory limit: 65536K 题目描述 一个由n * m 个格子组成的迷宫,起点是(1, 1), 终点是(n, m),每次可以向上下左右四个方 ...

  8. “There's no Qt version assigned to this project for platform ” - visual studio plugin for Qt

    1.find menu "Qt VS Tools", select Qt Options 2.add a new Qt version 3. right click the tar ...

  9. ZOJ 3706 Break Standard Weight 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5009 题目意思:给出两个mass:x 和 y,问如何将其中一个 ma ...

  10. 一步一步学Silverlight 2系列(29):使用Transform实现更炫的效果(上)

    概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支持框架语言Visual Basic, Visual C#, IronRuby, ...