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. hadoop2.x学习笔记(一):YARN

    一.YARN产生的背景 MapReduce1.x存在的问题:单点故障&节点压力大不易扩展. 资源利用率&成本 催生了YARN的诞生  不同计算框架可以共享同一个HDFS集群上的数据,享 ...

  2. 如何移动 nuget 缓存文件夹

    本文告诉大家如何移动 nuget 缓存文件夹. 因为 nuget 文件夹一般比较大,现在我的 nuget 文件夹有 10 G,默认的 nuget 文件夹是在C盘,所以需要移动他. 可以使用下面的代码查 ...

  3. CEF加载FLASH插件时弹出CMD命令行窗口的问题

    这个是flash插件的一个bug,CEF(chromium系列浏览器)关闭sandbox第一次加载flash插件就会跳出这样的一个提示,在Google官方也看到了chromium的issue: 解决方 ...

  4. Java基于ssm框架的restful应用开发

    Java基于ssm框架的restful应用开发 好几年都没写过java的应用了,这里记录下使用java ssm框架.jwt如何进行rest应用开发,文中会涉及到全局异常拦截处理.jwt校验.token ...

  5. Ubuntu16.04 LTS上安装Go1.10

    原因 Ubuntu资源库上默认使用的是Go1.6.2版本,给最新版本代码编译带来了不少问题.本文就记录下在Ubuntu下直接安装Go最新版1.10的步骤. 准备工作 1.卸载已有版本 # 卸载已经安装 ...

  6. java中对JVM的深度解析、调优工具、垃圾回收

    jdk自带的JVM调优工具 jvm监控分析工具一般分为两类,一种是jdk自带的工具,一种是第三方的分析工具.jdk自带工具一般在jdk bin目录下面,以exe的形式直接点击就可以使用,其中包含分析工 ...

  7. 【转】HttpServletRequestWrapper 实现xss注入

    这里说下最近项目中我们的解决方案,主要用到commons-lang3-3.1.jar这个包的org.apache.commons.lang3.StringEscapeUtils.escapeHtml4 ...

  8. Golang 模板

    最近又尝试了一下 Golang 的 Template,发现一般功能都满足了,而且语法也相对比较简单,所以稍作总结.在 Go语言中,模板有 text/template 和 html/template 两 ...

  9. Linux 线程调度与优先级

    [转] http://blog.chinaunix.net/uid-20788636-id-1841334.html http://blog.chinaunix.net/uid-20788636-id ...

  10. XSS学习(未完..)

    前言 XSS 漏洞原理非常简单,实际应用中非常灵活,于是通过 prompt(1) to win 来学习学习 正文 工具 分析正则表达式 https://regex101.com/ http://xss ...