[HNOI2011]Problem B
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的更多相关文章
- [bzoj2302][HNOI2011]problem c 递推,dp
[HAOI2011]Problem c Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 949 Solved: 519[Submit][Status] ...
- bzoj-2338 2338: [HNOI2011]数矩形(计算几何)
题目链接: 2338: [HNOI2011]数矩形 Time Limit: 20 Sec Memory Limit: 128 MB Description Input Output 题意: 思路 ...
- CJOJ 1331 【HNOI2011】数学作业 / Luogu 3216 【HNOI2011】数学作业 / HYSBZ 2326 数学作业(递推,矩阵)
CJOJ 1331 [HNOI2011]数学作业 / Luogu 3216 [HNOI2011]数学作业 / HYSBZ 2326 数学作业(递推,矩阵) Description 小 C 数学成绩优异 ...
- ●BZOJ 2329 [HNOI2011]括号修复.cpp
题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2329 题解: Splay 类似 BZOJ 2329 [HNOI2011]括号修复 只是多了一 ...
- bzoj千题计划222:bzoj2329: [HNOI2011]括号修复(fhq treap)
http://www.lydsy.com/JudgeOnline/problem.php?id=2329 需要改变的括号序列一定长这样 :)))((( 最少改变次数= 多余的‘)’/2 [上取整] + ...
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- 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 ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
随机推荐
- 蓝牙HID协议笔记【转】
蓝牙HID协议笔记 转自:http://blog.sina.com.cn/s/blog_69b5d2a50101emll.html 1.概述 The Human Interface Devic ...
- centos6.7环境下kvm虚拟机之virt-install和virsh及virt-manager工具的使用
virt-install工具的使用: virt-install是一个命令行工具,它能够为KVM.Xen或其它支持libvrit API的hypervisor创建虚拟机并完成GuestOS安装:此外,它 ...
- centos下常用文件管理命令
fdisk d 删除分区 n:新建一个分区 p:列出已有分区 t:调整分区ID l:列出内核支持的分区id w:保存退出 q:不保存退出 ...
- 100以内的质数(for和if)
- css3图片旋转
<!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...
- WPS for Linux
https://www.cnblogs.com/gisalameda/p/6839482.html
- Laravel Eloquent 自定义返回字段
返回指定字段 Book::select("price", "name")->all(); 返回关系字段关联的属性 Book::select("p ...
- 约数 求反素数bzoj1053 bzoj1257
//约数 /* 求n的正约数集合:试除法 复杂度:O(sqrt(n)) 原理:扫描[1,sqrt(N)],尝试d能否整除n,若能,则N/d也能 */ ],m=; ;i*i<=n;i++){ ){ ...
- ural1989 单点更新+字符串hash
正解是双哈希,不过一次哈希也能解决.. 然后某个数字就对应一个字符串,虽然有些不同串对应同一个数字,但是概率非常小,可以忽略不计.从左到右.从右到左进行两次hash,如果是回文串,那么对应的整数必定存 ...
- pytest二:setup和teardown
用例运行级别 模块级(setup_module/teardown_module)开始于模块始末,全局的 函数级(setup_function/teardown_function)只对函数用例生效(不在 ...