Pave the Parallelepiped CodeForces - 1007B (计数)
大意: 给定A,B,C, 求有多少个三元组$(a,b,c)$, 满足$a \le b \le c$, 且以若干个$(a,b,c)$为三边的长方体能填满边长(A,B,C)的长方体.
暴力枚举出$A,B,C$的所有整除关系的数量, 这样可以避免重复计数, 最后再用可重组合统计一下结果
#include <iostream> #include <algorithm> #include <math.h> #include <cstdio> #include <set> #include <map> #include <string> #include <vector> #include <string.h> #include <queue> #define PER(i,a,n) for(int i=n;i>=a;--i) #define REP(i,a,n) for(int i=a;i<=n;++i) #define hr cout<<'\n' #define pb push_back #define mid ((l+r)>>1) #define lc (o<<1) #define rc (lc|1) #define ls lc,l,mid #define rs rc,mid+1,r #define x first #define y second #define io std::ios::sync_with_stdio(false); #define endl '\n' using namespace std; typedef unsigned long long ll; typedef pair<int,int> pii; const int P = 1e9+7; ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;} ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;} void exgcd(ll a,ll b,ll &d,ll &x,ll &y){b?exgcd(b,a%b,d,y,x),y-=a/b*x:x=1,y=0,d=a;} ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;} //head const int N = 1e5+10, S = 7; int c[10], f[N]; ll C(int n, int m) { ll r = 1; REP(i,1,m) r*=n,--n; REP(i,1,m) r/=i; return r; } int check(int a,int b,int c) { if((a&1)&&(b&2)&&(c&4)) return true; if((a&1)&&(c&2)&&(b&4)) return true; if((b&1)&&(a&2)&&(c&4)) return true; if((b&1)&&(c&2)&&(a&4)) return true; if((c&1)&&(a&2)&&(b&4)) return true; if((c&1)&&(b&2)&&(a&4)) return true; return false; } void work() { int x, y, z; scanf("%d%d%d", &x, &y, &z); int xy=gcd(x,y),yz=gcd(y,z),xz=gcd(z,x),xyz=gcd(z,xy); c[7]=f[xyz]; c[6]=f[xy]-c[7]; c[5]=f[xz]-c[7]; c[3]=f[yz]-c[7]; c[4]=f[x]-c[5]-c[6]-c[7]; c[2]=f[y]-c[6]-c[3]-c[7]; c[1]=f[z]-c[5]-c[3]-c[7]; ll ans = 0; REP(i,0,7)REP(j,i,7)REP(k,j,7) if (check(i,j,k)) { int u[10]={}; ++u[i],++u[j],++u[k]; ll t = 1; REP(i,1,7) if (u[i]) t*=C(c[i]+u[i]-1,u[i]); ans += t; } printf("%llu\n", ans); } int main() { REP(i,1,N-1) for (int j=i; j<N; j+=i) ++f[j]; int t; scanf("%d", &t); while (t--) work(); }
Pave the Parallelepiped CodeForces - 1007B (计数)的更多相关文章
- codeforces 1007B Pave the Parallelepiped
codeforces 1007B Pave the Parallelepiped 题意 题解 代码 #include<bits/stdc++.h> using namespace std; ...
- CF1007B Pave the Parallelepiped 容斥原理
Pave the Parallelepiped time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- [CF1007B]Pave the Parallelepiped[组合计数+状态压缩]
题意 \(t\) 组询问,给你 \(A, B, C\) ,问有多少组三元组 \((a, b, c)\) 满足他们任意排列后有: \(a|A,\ b|B,\ c|C\) . \(A,B,C,t\leq ...
- CodeForces 558E(计数排序+线段树优化)
题意:一个长度为n的字符串(只包含26个小字母)有q次操作 对于每次操作 给一个区间 和k k为1把该区间的字符不降序排序 k为0把该区间的字符不升序排序 求q次操作后所得字符串 思路: 该题数据规模 ...
- Codeforces 1065E(计数)
题目链接 题意 限定字符串长度为$n$,字符集规模为$A$,以及$m$个数字$b$,对于任意数字$bi$满足长度为$bi$的前缀和后缀先反转再交换位置后形成的新串与原串视作相等,问存在多少不同串. 思 ...
- Bug in Code CodeForces - 420C (计数,图论)
大意: 给定$n$结点无向图, 共n条边, 有重边无自环, 求有多少点对(u,v), 满足经过u和v的边数>=p 可以用双指针先求出所有$deg_u+deg_v \ge p$的点对, 但这样会多 ...
- A Creative Cutout CodeForces - 933D (计数)
大意:给定$n$个圆, 圆心均在原点, 第$k$个圆半径为$\sqrt{k}$ 定义一个点的美丽值为所有包含这个点的圆的编号和 定义函数$f(n)$为只有$n$个圆时所有点的贡献,求$\sum_{k= ...
- codeforces 466C 计数 codeforces 483B 二分 容斥
题意:给你n个数,将他们分成连续的三个部分使得每个部分的和相同,求出分法的种数. 思路:用一个数组a[i]记下从第一个点到当前i点的总和.最后一个点是总和为sum的点,只需求出总和为1/3sum的点和 ...
- Scalar Queries CodeForces - 1167F (计数,树状数组)
You are given an array $a_1,a_2,…,a_n$. All $a_i$ are pairwise distinct. Let's define function $f(l, ...
随机推荐
- MySQL实现根据当前ID读取上一条和下一条记录
以下为MySQL语句演示: SELECT * FROM t_news AS n ORDER BY n.`News_ID` 当前ID为4,读取上一条记录: ,; 当前ID为4,读取下一条记录: ,; 其 ...
- Centos6.5SSH登录使用google二次验证
一般ssh登录服务器,只需要输入账号和密码,但为了更安全,在账号和密码之间再增加一个google的动态验证码.谷歌身份验证器生成的是动态验证码,默认30秒更新 工具/原料 CentOS 6.5 X ...
- CodeForces 25C(Floyed 最短路)
F - Roads in Berland Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I6 ...
- Day23 ajax
AJAX AJAX概述 1 什么是AJAX AJAX(Asynchronous Javascript And XML)翻译成中文就是"异步Javascript和XML".即使用Ja ...
- Mybatis三剑客之mybatis-generator配置
mybatis插件在这里: 然后把generatorConfig.xml文件放在resources下: <?xml version="1.0" encoding=" ...
- leetcode——Search for a Range 排序数组中寻找目标下标范围(AC)
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- Struct2小结:
Action小结: 实现一个Action的最常用的方式:从ActionSupport继承: DMI动态方法调用,减少配置内容: 通配符 *_* ({1},{2})的使用更方便: 接收参数的方法(一般用 ...
- Ubuntu下virtualenv 的安装及使用
按照这个命令做下来基本是ok的. https://blog.csdn.net/qq_33371343/article/details/78047853
- 关于eval 与new Function 到底该选哪个?
废话不多说,直接上测试代码 复制代码 代码如下: var aa = "{name:'cola',item:[{age:11},{age:22},{age:23},{age:23}]}&quo ...
- Linux 查看系统所有用户
grep bash /etc/passwd Linux 查看系统所有用户