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. ZOJ 1586 QS Network(Kruskal算法求解MST)

    题目: In the planet w-503 of galaxy cgb, there is a kind of intelligent creature named QS. QScommunica ...

  2. Node.js文件操作一

    Node.js和其他语言一样,也有文件操作.先不说node.js中的文件操作,其他语言的文件操作一般也都是有打开.关闭.读.写.文件信息.新建删除目录.删除文件.检测文件路径等.在node.js中也是 ...

  3. IDF实验室-简单的js解密

    根据加密方法推算解密方法,补全如下 <script> /** * Pseudo md5 hash function * @param {string} string * @param {s ...

  4. sendsms短信验证功能实现代码

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name ...

  5. Spring Aop之@Before、@After、@Around、@AfterReturning

    在项目中使用到了@Aspect注解,故研究了下与其配套的几个注解,将测试结果记录下来 import org.aspectj.lang.JoinPoint; import org.aspectj.lan ...

  6. win10 uwp unix timestamp 时间戳 转 DateTime

    有时候需要把网络的 unix timestamp 转为 C# 的 DateTime ,在 UWP 可以如何转换? 转换函数可以使用下面的代码 private static DateTime UnixT ...

  7. MySql社区版和企业版的区别

    1.社区版的免费,出问题MySql公司概不负责,是企业版的测试版,功能却没有企业版功能完善. 2.企业版的收费,并且价格不便宜,标准版2000美元,企业版5000美元,高级集群版10000美元(6万人 ...

  8. python3.3 unicode(encode&decode)

    最近在用python写多语言的一个插件时,涉及到python3.x中的unicode和编码操作,本文就是针对编码问题研究的汇总,目前已开源至github.以下内容来自项目中的README. 1 ASC ...

  9. JAVA非静态成员变量之死循环

    1.非静态成员变量 当成员变量为非静态成员变量且对当前类进行实例化时,将会产生死循环 例子: public class ConstructorCls { private ConstructorCls ...

  10. .NET中的异步编程

    开篇 异步编程是程序设计的重点也是难点,还记得在刚开始接触.net的时候,看的是一本c#的Winform实例教程,上面大部分都是教我们如何使用Winform的控件以及操作数据库的实例,那时候做的基本都 ...