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. oracle 报错归纳总结

    1.ORA-00904 正常情况下是找不到字段(大概率字段名字错了) 还有一种比较特别的情况实在设计DB的时候,字段小写,在sql查询工具自动提示的时候都是大写,造成字段找不到的情况.

  3. mybatis在mysql中的分页扩展

    applicationContext.xml <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlS ...

  4. 用正则表达式修改html字符串的所有div的style样式

    最近项目中有一接口返回的一个字段是html格式的字符串,里边每个div中style的高度是固定的px,然后再手机端显示的时候发现,div中的内容重叠了:效果图如下: 对应的div如下: 由于高度固定, ...

  5. java泛型详解(加一点语法糖)

    首先请看如下代码: public class Test{ public static void main(String str[]) { Hashtable h =new Hashtable(); h ...

  6. JVM类加载器及Java类的生命周期

    预定义类加载器(三种): 启动(Bootstrap)类加载器: 是用本地代码实现的类装入器,它负责将<Java_Runtime_Home>/lib下面的类库加载到内存中(比如rt.jar) ...

  7. UBuntu安装配置记录

    记得是06年左右第一次安装的 Linux,当时是下载的 Fedora镜像,版本已经记不清了,在商业街的电脑维修店刻的盘,回来后兴冲冲地和XP一起安装的双系统.其实就是直接的体验了一把,只是看了看X-W ...

  8. YII中利用urlManager将URL改写成restful风格

    这里主要涉及url显示样式 1.打开config文件夹下面的mian.php   2.修改内容   如把地址http://www.test.com/index.php?r=site/page/sid/ ...

  9. 百度 echarts K线图使用

    看个效果图先 首先在需要插入图例的HTML中嵌入 <div id="main" style="height:400px"></div> ...

  10. SESSION机制(转)

    转自:http://www.cnblogs.com/zyf-zhaoyafei/p/4477175.html 一:Session与Cookie Session:在服务器端创建并存放在服务器的内存中的, ...