CF1007B Pave the Parallelepiped 容斥原理
2 seconds
256 megabytes
standard input
standard output
You are given a rectangular parallelepiped with sides of positive integer lengths AA, BB and CC.
Find the number of different groups of three integers (aa, bb, cc) such that 1≤a≤b≤c1≤a≤b≤c and parallelepiped A×B×CA×B×C can be paved with parallelepipeds a×b×ca×b×c. Note, that all small parallelepipeds have to be rotated in the same direction.
For example, parallelepiped 1×5×61×5×6 can be divided into parallelepipeds 1×3×51×3×5, but can not be divided into parallelepipeds 1×2×31×2×3.
The first line contains a single integer tt (1≤t≤1051≤t≤105) — the number of test cases.
Each of the next tt lines contains three integers AA, BB and CC (1≤A,B,C≤1051≤A,B,C≤105) — the sizes of the parallelepiped.
For each test case, print the number of different groups of three points that satisfy all given conditions.
4
1 1 1
1 6 1
2 2 2
100 100 100
1
4
4
165
In the first test case, rectangular parallelepiped (1,1,1)(1,1,1) can be only divided into rectangular parallelepiped with sizes (1,1,1)(1,1,1).
In the second test case, rectangular parallelepiped (1,6,1)(1,6,1) can be divided into rectangular parallelepipeds with sizes (1,1,1)(1,1,1), (1,1,2)(1,1,2), (1,1,3)(1,1,3) and (1,1,6)(1,1,6).
In the third test case, rectangular parallelepiped (2,2,2)(2,2,2) can be divided into rectangular parallelepipeds with sizes (1,1,1)(1,1,1), (1,1,2)(1,1,2), (1,2,2)(1,2,2) and (2,2,2)(2,2,2).
这题目其实求的就是a的因子乘b的因子乘c的因子
所以重点是算出a,b,c的因子
但是中间会出现重复的情况,比如(1,1,2),(1,2,1)是同一种情况
所以我们还要用容斥原理去掉这种情况
情况分为四种:a,b重负的情况;a,c重复的情况;b,c重复的情况;a,b,c重复的情况
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define A 0
#define B 1
#define C 2
#define AB 3
#define BC 4
#define AC 5
#define ABC 6
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e5;
const int mod = 10000007;
typedef long long ll;
ll t, a, b, c, kt[5],p[10], nu[maxn+10], num[maxn+10];
ll gcd( ll a, ll b) {
return b==0?a:gcd(b,a%b);
}
map<ll,ll>mm;
vector<ll> va, vb, vc;
void init() { //预处理每个数因子的数量
for( ll i = 1; i <= maxn; i ++ ) {
for( ll j = i; j <= maxn; j +=i ) {
nu[j] ++;
}
}
va.push_back(A); va.push_back(AB);
va.push_back(AC); va.push_back(ABC); vb.push_back(B); vb.push_back(AB);
vb.push_back(BC); vb.push_back(ABC); vc.push_back(C); vc.push_back(AC);
vc.push_back(BC); vc.push_back(ABC);
} ll cal3( ll x) {
ll res = 0;
res += x + x*(x-1) + x*(x-1)*(x-2)/6;//三部分取相同,两部分取相同,三部分都不同
return res;
} ll cal2( ll x ) {
ll res = 0;
res += x + x*(x-1)/2;//两部分相同,两部分不同
return res;
}
int main() {
init();
cin >> t;
while(t--)
{
cin >> a >> b >> c;
ll ab = gcd(a,b), bc = gcd(b,c), ac = gcd(a,c);
ll abc = gcd(ab,c);
ll nABC = nu[abc];
ll nAB = nu[ab] - nABC, nBC = nu[bc] - nABC, nAC = nu[ac] - nABC;
ll nA = nu[a] - nAB - nAC - nABC, nB = nu[b] - nAB - nBC - nABC;
ll nC = nu[c] - nAC - nBC - nABC;
num[ABC] = nABC;
num[AB] = nAB, num[AC] = nAC, num[BC] = nBC;
num[A] = nA, num[B] = nB, num[C] = nC;
ll ans = 0;
mm.clear();
for( ll i = 0; i < va.size(); i ++ ) {
for( ll j = 0; j < vb.size(); j ++ ) {
for( ll k = 0; k < vc.size(); k ++ ) {
kt[0] = va[i], kt[1] = vb[j], kt[2] = vc[k];
sort( kt, kt+3 );
ll x = kt[0], y = kt[1], z = kt[2];
ll tmp = 0;
for( ll l = 0; l < 3; l ++ ) {
tmp=1ll*tmp*maxn+1ll*kt[l];
}
if( mm[tmp] ) continue;///打标记去重
mm[tmp] = 1;
if( x == y && y == z )
ans += cal3(num[x]);
else if( x == y )
ans += num[z]*cal2(num[x]);
else if( y == z )
ans += num[x]*cal2(num[y]);
else ans += num[x]*num[y]*num[z];
}
}
}
cout << ans << endl;
}
return 0;
}
CF1007B Pave the Parallelepiped 容斥原理的更多相关文章
- [CF1007B]Pave the Parallelepiped[组合计数+状态压缩]
		
题意 \(t\) 组询问,给你 \(A, B, C\) ,问有多少组三元组 \((a, b, c)\) 满足他们任意排列后有: \(a|A,\ b|B,\ c|C\) . \(A,B,C,t\leq ...
 - codeforces 1007B Pave the Parallelepiped
		
codeforces 1007B Pave the Parallelepiped 题意 题解 代码 #include<bits/stdc++.h> using namespace std; ...
 - CF1008D Pave the Parallelepiped
		
容斥原理 解法一: 其他容斥原理的题也可以用这种思想 先把$A$,$B$,$C$分解因数 一种很暴力的想法是,将这些因数分成若干个集合(画出韦恩图),然后对有序数组的三个数分别枚举其位于哪一个集合中 ...
 - Pave the Parallelepiped CodeForces - 1007B (计数)
		
大意: 给定A,B,C, 求有多少个三元组$(a,b,c)$, 满足$a \le b \le c$, 且以若干个$(a,b,c)$为三边的长方体能填满边长(A,B,C)的长方体. 暴力枚举出$A,B, ...
 - hdu4059 The Boss on Mars(差分+容斥原理)
		
题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设 则 为一阶差分. 二阶差分: n阶差分: 且可推出 性质: 1. ...
 - hdu2848 Visible Trees (容斥原理)
		
题意: 给n*m个点(1 ≤ m, n ≤ 1e5),左下角的点为(1,1),右上角的点(n,m),一个人站在(0,0)看这些点.在一条直线上,只能看到最前面的一个点,后面的被档住看不到,求这个人能看 ...
 - BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
		
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
 - BZOJ 2440: [中山市选2011]完全平方数 [容斥原理 莫比乌斯函数]
		
2440: [中山市选2011]完全平方数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3028 Solved: 1460[Submit][Sta ...
 - ACM/ICPC 之 中国剩余定理+容斥原理(HDU5768)
		
二进制枚举+容斥原理+中国剩余定理 #include<iostream> #include<cstring> #include<cstdio> #include&l ...
 
随机推荐
- spring boot中的声明式事务管理及编程式事务管理
			
这几天在做一个功能,具体的情况是这样的: 项目中原有的几个功能模块中有数据上报的功能,现在需要在这几个功能模块的上报之后生成一条消息记录,然后入库,在写个接口供前台来拉取消息记录. 看到这个需求,首先 ...
 - powermockito单元测试之深入实践
			
概述 由于最近工作需要, 在项目中要做单元测试, 以达到指定的测试用例覆盖率指标.项目中我们引入的powermockito来编写测试用例, JaCoCo来监控单元测试覆盖率.关于框架的选择, 网上讨论 ...
 - 自己学习并保存的一些shell命令
			
摘要: 在学习过程中,不免会遇到有些命令,那种需要的,但是你没有掌握的命令.为了节省时间,担心忘记这些,特开辟这个随笔,随时记录用到的一些命令.那么常用的不提了,自己去收集吧~ 1.文件按日期排序 应 ...
 - 给你的SpringBoot做埋点监控--JVM应用度量框架Micrometer
			
JVM应用度量框架Micrometer实战 前提 spring-actuator做度量统计收集,使用Prometheus(普罗米修斯)进行数据收集,Grafana(增强ui)进行数据展示,用于监控生成 ...
 - MTFlexbox自动化埋点探索
			
1. 背景 跨平台动态化技术是目前移动互联网领域的重点关注方向,它既能节约人力,又能实现业务快速上线的需求.经过十年的发展,美团App已经变成了一个承载众多业务的超级平台,众多的业务方对业务形态的快速 ...
 - java秒杀系列(2)- 页面静态化技术
			
前言 通过代码片段分别介绍服务端渲染.客户端渲染.对象缓存三种方式的写法. 代码片段仅供参考,具体实现需要根据业务场景自行适配,但思想都是一样. 一.服务端渲染方式 1.接口返回html页面的设置 @ ...
 - 简述关于ASP.NET MVC与.NET CORE 的区别
			
简述关于ASP.NET MVC与.NET CORE的区别1.关于ASP.NET 关于MVC刚开始接触这个技术的时候我经常不理解他们的名字,我相信许多学ASP.NET开发人员开始接触MVC应该也和我一样 ...
 - php Basic HTTP与Digest HTTP 应用
			
Basic HTTP 认证范例 <?php //Basic HTTP 认证 if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authen ...
 - T-SQL基础语句
			
存储过程允许标准组件式编程(模块化设计) 存储过程能够实现快速的执行速度 存储过程能够减少网络流量 存储过程可被作为一种安全机制充分利用 在SQL Server 的系列版本中存储过程分为两类:系统提供 ...
 - linux系统磁盘满了,怎么解决?
			
1.使用命令:df -lk 或 df -hl 发现果然有个磁盘已满 2.使用命令:du --max-depth=1 -h 查找大文件,发现/home文件夹下有17G的东西,因为我的apache是装在 ...