Description:

给定\(a\),\(b\),\(c\),\(d\),\(k\)

求:

\(\sum_{i=a}^{b} \sum_{j=c}^{d} gcd(i,j)==k\)

\(T\)组询问

Hint:

均\(<=5e4\)

Solution:

不就比\(zap-query\)多了个下界嘛,容斥即可

#include<bits/stdc++.h>
using namespace std;
const int mxn=1e5+5;
int T,tot,mu[mxn],vis[mxn],p[mxn],f[mxn];
int sum[mxn]; void sieve(int lim)
{
mu[1]=1;
for(int i=2;i<=lim;++i) {
if(!vis[i]) mu[i]=-1,p[++tot]=i;
for(int j=1;j<=tot;++j) {
if(p[j]*i>lim) break;
vis[p[j]*i]=1;
if(i%p[j]==0) {
mu[i*p[j]]=0;
break;
}
mu[p[j]*i]=-mu[i];
}
}
for(int i=1;i<=lim;++i) sum[i]=sum[i-1]+mu[i];
} int solve(int n,int m,int k)
{
if(n>m) swap(n,m); int ans=0;
for(int l=1,r;l<=n;l=r+1) {
r=min(n/(n/l),m/(m/l));
ans+=1ll*(sum[r]-sum[l-1])*(n/l)*(m/l);
}
return ans;
} int main()
{
scanf("%d",&T);
sieve(50000);
while(T--) {
int n,m,x,y,k;
scanf("%d%d%d%d%d",&n,&m,&x,&y,&k); --n,--x;
n/=k,m/=k,x/=k,y/=k;
printf("%d\n",solve(m,y,k)-solve(n,y,k)-solve(m,x,k)+solve(n,x,k));
}
return 0;
}

[HNOI2011]Problem B的更多相关文章

  1. [bzoj2302][HNOI2011]problem c 递推,dp

    [HAOI2011]Problem c Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 949  Solved: 519[Submit][Status] ...

  2. bzoj-2338 2338: [HNOI2011]数矩形(计算几何)

    题目链接: 2338: [HNOI2011]数矩形 Time Limit: 20 Sec  Memory Limit: 128 MB Description Input   Output 题意: 思路 ...

  3. CJOJ 1331 【HNOI2011】数学作业 / Luogu 3216 【HNOI2011】数学作业 / HYSBZ 2326 数学作业(递推,矩阵)

    CJOJ 1331 [HNOI2011]数学作业 / Luogu 3216 [HNOI2011]数学作业 / HYSBZ 2326 数学作业(递推,矩阵) Description 小 C 数学成绩优异 ...

  4. ●BZOJ 2329 [HNOI2011]括号修复.cpp

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2329 题解: Splay 类似 BZOJ 2329 [HNOI2011]括号修复 只是多了一 ...

  5. bzoj千题计划222:bzoj2329: [HNOI2011]括号修复(fhq treap)

    http://www.lydsy.com/JudgeOnline/problem.php?id=2329 需要改变的括号序列一定长这样 :)))((( 最少改变次数= 多余的‘)’/2 [上取整] + ...

  6. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  7. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  8. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  9. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

随机推荐

  1. Linux中涉及到计算优先级及其他问题

    比如计算矩形周长: a= b= echo `expr \* $((a+b))` 1.expr外要使用反引号,且expr只支持整数计算,如果涉及到浮点数计算要采用下面方法 2.优先计算a+b时,要使用双 ...

  2. centos 6.5内核编译步骤及配置详解

    1.准备并加压内核安装包:linux-3.13.2.tar.xz # tar xf linux-3.13.2.tar.xz -C /usr/src # cd /usr/src/ # ln -sv li ...

  3. 通达OA批量处理没有结束但前台显示已经结束的流程

    问题描述: 通达OA系统出现大量流程没有结束,系统显示结束的问题 通过查询操作系统日志,数据库日志,包括程序日志没有发现异常,通过观察发现大量的流程结束时间都是在2016-02-16 17:32:XX ...

  4. 通达OA系统故障解决案例记录

    案例1: 现象:在人员访问量大的时候OA系统经卡死,并且经常宕机,需要启动apache服务 优化配置如下: D:\MYOA\conf\http.conf 修改参数如下: <IfModule mp ...

  5. swift的一些知识点(不断完善中)

    首先,隆重推荐文章http://www.infoq.com/cn/articles/swift-brain-gym-optional swift 烧脑体操!目前有4篇文章,说的都很好! 1. 应该充分 ...

  6. python for dl

    算是python的简明教程吧,总结的不错: https://zhuanlan.zhihu.com/p/24162430 python for opencv: https://zhuanlan.zhih ...

  7. VeeValidate配置中文的两种方法

    使用VeeValidate时遇到的问题,下面是我找到的一些解决办法: VeeValidate一直报错早不到addlocale方法 解决办法:1.卸载掉当前版本,重新安装低版本如2.0.0-rc.25  ...

  8. Reactor模型-多线程程版

    1.概述 在Reactor单线程版本的设计中,I/O任务乃至业务逻辑都由Reactor线程来完成,这无疑增加了Reactor线程的负担,高负载情况下必然会出现性能瓶颈.此外,对于多处理器的服务器来说, ...

  9. cf932d 树上倍增

    题解链接 https://blog.csdn.net/my_sunshine26/article/details/79338601 感觉能做,但是倍增还不是很熟悉,回头再补

  10. pytest五:fixture_autouse=True

    平常写自动化用例会写一些前置的 fixture 操作,用例需要用到就直接传该函数的参数名称就行了.当用例很多的时候,每次都传返个参数,会比较麻烦.fixture 里面有个参数 autouse,默讣是 ...