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. AOP和OOP的区别

    AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. AOP与OOP是面向不同领域的两种设计思想. ...

  2. HDOJ1006

    #include <cstdio>#include <algorithm>using namespace std;const double UB=43200;const dou ...

  3. 给EasyUi的Form加入自己主动填充部分输入框的方法

    依据项目须要,基于获取的数据对Form的部分输入框进行填充,而默认的EasyUI的Form 没有该方法.仅仅能一个输入框一个输入框的直接赋值,为此添加了Form对象的setValues,实现依据给定的 ...

  4. HDU 6040 Hints of sd0061 nth_element函数

    Hints of sd0061 Problem Description sd0061, the legend of Beihang University ACM-ICPC Team, retired ...

  5. 在C/C++中使用VLD检测内存泄漏

    VLD地址:https://kinddragon.github.io/vld/ 若出现内存泄漏,VS输出窗口会有如下提示: 若要确定造成内存泄漏的代码位置,仅需进入工程属性->链接器->调 ...

  6. struts2 过滤器

    Chain.doFilter的作用就是继续请求的传递,可传递给下一个filter也可传递给目标页面 如左侧传递给filter2,但fiter2使用上面或者下面的方法将倾情重定向到一个新的页面,而不再传 ...

  7. css3中我们不知道的一些属性

    1.图片作为边框:border-image; 2.圆角问题:border-radius:上.下.左.右: 3.字体的阴影与自动换行: 阴影: h1 {text-shadow: 5px 5px 5px ...

  8. 进程调度函数schedule()分析

    1.功能简述: 最主要作用就是 从就绪进程中选择一个优先级最高的进程来代替当前进程运行.   2.代码分析 schedule();      struct task_struct *tsk = cur ...

  9. atexit函数的使用【学习笔记】

    #include "apue.h" static void my_exit1(void); static void my_exit2(void); int main(void) { ...

  10. POJ3268 Silver Cow Party —— 最短路

    题目链接:http://poj.org/problem?id=3268 Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total ...