codeforces 1007B Pave the Parallelepiped

题意

题解

代码

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
//--- const int N = 101010, M = 166; int a[3], cnt[8], d[N];
map<pair<pii, int>, bool> vis;
ll f[M], f2[N]; void init() {
rep(i, 1, M) {
rep(j, 1, i+1) f[i] += 1ll * j * (i - j + 1);
f2[i] = 1ll * i * (i+1) / 2;
}
rep(i, 1, N) {
for(int j = 1; j * j <= i; ++j) if(i%j==0) {
++d[i];
if(j != i/j) ++d[i];
}
}
} int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
init();
int T;
cin >> T;
while(T--) {
rep(i, 0, 3) cin >> a[i];
cnt[1] = d[a[0]];
cnt[2] = d[a[1]];
cnt[4] = d[a[2]];
cnt[3] = d[__gcd(a[0], a[1])];
cnt[5] = d[__gcd(a[0], a[2])];
cnt[6] = d[__gcd(a[1], a[2])];
cnt[7] = d[__gcd(__gcd(a[0], a[1]), a[2])];
cnt[3] -= cnt[7];
cnt[5] -= cnt[7];
cnt[6] -= cnt[7];
cnt[1] -= cnt[3] + cnt[5] + cnt[7];
cnt[2] -= cnt[3] + cnt[6] + cnt[7];
cnt[4] -= cnt[5] + cnt[6] + cnt[7];
ll ans = 0;
vis.clear();
rep(a, 1, 8) if(cnt[a] && (a&1)) rep(b, 1, 8) if(cnt[b] && (b>>1&1)) rep(c, 1, 8) if(cnt[c] && (c>>2&1)) {
int x[] = {a, b, c};
sort(x, x+3);
int i = x[0], j = x[1], k = x[2];
auto t = mp(mp(i, j), k);
if(vis[t]) continue;
vis[t] = 1;
if(i == j && i == k) {
ans += f[cnt[i]];
} else if(i == j) {
ans += f2[cnt[i]] * cnt[k];
} else if(i == k) {
ans += f2[cnt[i]] * cnt[j];
} else if(j == k) {
ans += f2[cnt[j]] * cnt[i];
} else {
ans += cnt[i] * cnt[j] * cnt[k];
}
}
cout << ans << endl;
}
return 0;
}

codeforces 1007B Pave the Parallelepiped的更多相关文章

  1. CF1007B Pave the Parallelepiped 容斥原理

    Pave the Parallelepiped time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  2. Pave the Parallelepiped CodeForces - 1007B (计数)

    大意: 给定A,B,C, 求有多少个三元组$(a,b,c)$, 满足$a \le b \le c$, 且以若干个$(a,b,c)$为三边的长方体能填满边长(A,B,C)的长方体. 暴力枚举出$A,B, ...

  3. [CF1007B]Pave the Parallelepiped[组合计数+状态压缩]

    题意 \(t\) 组询问,给你 \(A, B, C\) ,问有多少组三元组 \((a, b, c)\) 满足他们任意排列后有: \(a|A,\ b|B,\ c|C\) . \(A,B,C,t\leq ...

  4. CF1008D Pave the Parallelepiped

    容斥原理 解法一: 其他容斥原理的题也可以用这种思想 先把$A$,$B$,$C$分解因数 一种很暴力的想法是,将这些因数分成若干个集合(画出韦恩图),然后对有序数组的三个数分别枚举其位于哪一个集合中 ...

  5. Codeforces Round #138 (Div. 2) A. Parallelepiped

    A. Parallelepiped time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  6. Codeforces 1008D/1007B

    题意略. 思路: 由于这个长方体是可以翻转的,所以我们不必考虑小长方体3个维度的出处,反正3条边一定有长有短能分出大小. 现在我们来考虑A,B,C三个数字,如果它们3个产生的因子互不相同,分别产生了a ...

  7. Codeforces Gym 100002 B Bricks 枚举角度

    Problem B Bricks" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 ...

  8. Codeforces Round #143 (Div. 2) (ABCD 思维场)

    题目连链接:http://codeforces.com/contest/231 A. Team time limit per test:2 seconds memory limit per test: ...

  9. Codeforces Beta Round #1 A,B,C

    A. Theatre Square time limit per test:1 second memory limit per test:256 megabytes input:standard in ...

随机推荐

  1. 遇见CUBA CLI

    原文:Meet CLI for CUBA Platform 翻译:CUBA China CUBA-Platform 官网 : https://www.cuba-platform.com CUBA Ch ...

  2. [转]HTTP请求中的form data和request payload的区别

    本文转自:http://www.cnblogs.com/btgyoyo/p/6141480.html jQuery的ajax方法和post方法分别发送请求,在后台Servlet进行处理时结果是不一样的 ...

  3. WinForm 多语言处理

    多语言处理工具我使用的是  SailingEase .NET Resources Tool ,好处是导出一个Excel,把具体翻译工作交给专业的人来做,翻译ok后再导入,缺点就是后续更改麻烦,添加一个 ...

  4. 边框阴影box-shadow

    边框的阴影: 参数说明: box-shadow:1px 2px 3px 4px #ccc inset: 1px 从原点开始,沿x轴正方向的长度(倘若为负值,为沿x轴负方向的长度) 2px 从原点开始, ...

  5. [转]浅谈 JavaScript的原型对象与原型链

    看到这篇文章写的很好,转过来以便今后阅读. 原文地址:http://www.cnblogs.com/shuiyi/p/5305435.html 对于新人来说,JavaScript的原型是一个很让人头疼 ...

  6. SVN版本控制——SVN 合并的六种方式

    合并的工作是把主干或者分支上合并范围内的所有改动列出,并对比当前工作副本的内容,由合并者手工修改冲突,然后提交到服务器的相应目录里.如果当前工作副本是主干,则合并的范围是分支上的改动,如果工作副本是分 ...

  7. Docker(二):微服务教程

    Docker 是一个容器工具,提供虚拟环境.很多人认为,它改变了我们对软件的认识. 站在 Docker 的角度,软件就是容器的组合:业务逻辑容器.数据库容器.储存容器.队列容器......,Docke ...

  8. 2017年5月22日 HTML基础知识(一)

    一.Html 结构 1.1.HTML基本文档格式—<html> 标记 —<html>文档的头部好和主体内容 </html>  根标记 —<head> 文 ...

  9. react生命周期获取异步数据

    当react组件需要获取异步数据的时候,建议在ComponentDidMount周期里执行获取动作, 如果非异步数据,可以在ComponentWillMount获取 因为ComponentWillMo ...

  10. Scala + Thrift+ Zookeeper+Flume+Kafka配置笔记

    1. 开发环境 1.1. 软件包下载 1.1.1. JDK下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downl ...