HDU 1695 容斥
又是求gcd=k的题,稍微有点不同的是,(i,j)有偏序关系,直接分块好像会出现问题,还好数据规模很小,直接暴力求就行了。
/** @Date : 2017-09-15 18:21:35
* @FileName: HDU 1695 容斥 或 莫比乌斯反演.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8; LL pri[N];
LL mu[N];
LL sum[N];
int c = 0;
bool vis[N]; void prime()
{
MMF(vis);
MMF(sum);
mu[1] = 1;
for(int i = 2; i < N; i++)
{
if(!vis[i])
pri[c++] = i, mu[i] = -1;
for(int j = 0; j < c && i * pri[j] < N; j++)
{
vis[i * pri[j]] = 1;
if(i % pri[j] == 0)
{
mu[i * pri[j]] = 0;
break;
}
else mu[i * pri[j]] = -mu[i];
}
}
sum[0] = 0;
for(int i = 1; i < N; i++)
sum[i] += sum[i - 1] + mu[i];
} LL get_sum(LL n, LL m)
{
if(n > m) swap(n, m);
int mi = min(n, m);
LL ans = 0;
for(int i = 1, last; i <= mi; i++, last = last + 1)
{
last = min(n/(n/i), m/(m/i));//由于有重复情况 不能直接分块?
ans += (LL)(n / i) * (m / i) * (sum[i] - sum[i - 1]);
}
return ans;
} int main()
{
int T;
prime();
cin >> T;
int cnt = 0;
while(T--)
{
LL a, b, c, d, k;
scanf("%lld%lld%lld%lld%lld", &a, &b, &c, &d, &k);
if(k == 0)
{
printf("Case %d: 0\n", ++cnt);
continue;
}
a = (a - 1) / k;
b = b / k;
c = (c - 1) / k;
d = d / k;
LL ans = get_sum(a, c) + get_sum(b, d) - get_sum(a, d) - get_sum(b, c) - get_sum(min(b,d), min(b,d)) / 2;
printf("Case %d: %lld\n", ++cnt, ans);
/*LL ans = 0;
LL t = 0;
for(int i = 1; i <= b; i++)
ans += (b / i) * (d / i) * mu[i];
for(int i = 1; i <= d; i++)
t += (min(b,d)/ i) * (min(b, d) / i) * mu[i];
printf("Case %d: %lld\n", ++cnt, ans - t / 2);*/
}
return 0;
}
HDU 1695 容斥的更多相关文章
- HDU 4135 容斥
问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. ...
- HDU 2841 容斥 或 反演
$n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 284 ...
- HDU 4059 容斥初步练习
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- hdu 1220 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Co-prime HDU - 4135_容斥计数
Code: #include<cstdio> #include<cstring> #include<cmath> #include<iostream> ...
- How many integers can you find HDU - 1796_容斥计数
Code: #include<cstdio> using namespace std; typedef long long ll; const int R=13; ll a[R]; ll ...
- HDU 1695 GCD 容斥
GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...
- hdu 1695 GCD 欧拉函数 + 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1695 要求[L1, R1]和[L2, R2]中GCD是K的个数.那么只需要求[L1, R1 / K] 和 [L ...
- HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演
GCD Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
随机推荐
- 团队作业the end
GitHub 王德钊 李镇平 陈启昌 黄益颂 汪倍民 演示动态图:为避免现场演示翻车,各个团队需要给出项目各个功能点运行的git图. 还在肝: 分工协作:团队的成员如何分工协作的?对项目的贡献如何(用 ...
- 读我是一只IT小小鸟有感
进入大学半年了,每个人都说软件工程是一个非常有前途的高薪职业,但我这半年来都很迷茫,看不清自己的未来,不知道如何度过接下来的三年半时光,虽然我也认为软件工程是有前途的专业,但是经过一学期的学习,发现不 ...
- spark作用流程
原文:https://www.cnblogs.com/asura7969/p/8441471.html https://blog.csdn.net/xu__cg/article/details/700 ...
- 01_Java基础_第1天(Java概述、环境变量、注释、关键字、标识符、常量)_讲义
今日内容介绍 1.Java开发环境搭建 2.HelloWorld案例 3.注释.关键字.标识符 4.数据(数据类型.常量) 01java语言概述 * A: java语言概述 * a: Java是sun ...
- 将 Spring 和 Hibernate 与 WebSphere Application Server 一起使用
本文摘要 如果您考虑将 Spring 或 Hibernate 与 IBM® WebSphere® Application Server 一起使用,则本文向您阐述了如何配置这些框架,以适用于 WebSp ...
- 课堂学习Scrum站立会议
项目名称:连连看游戏 小组成员:张政,张金生,李权,武志远 Master:张政 站立会议内容 1.已完成的内容 windows下的基本用户页面,实现了多个BUTTON下7*12的页面布局,但是出现了b ...
- MyEclipse+SSH开发环境配置
MyEclipse+Struts+Hibernate+Mysql开发环境配置 软件: jdk-6u22-windows-x64.exe apache-tomcat-6.0.29.exe mysql-5 ...
- Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错,
Linux下编译程序时,经常会遇到“undefined reference to XXX” 报错, 这里总结一些可能的原因和解决方案,给需要的朋友: 说道undefined reference err ...
- webgl example1
<!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- .net下使用NPOI读取Excel表数据
这里只写MVC下的情况 public ActionResult Index() { var path = Server.MapPath(@"/content/user.xlsx") ...