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, ...
随机推荐
- Golang OOP、继承、组合、接口
http://www.cnblogs.com/jasonxuli/p/6836399.html 传统 OOP 概念 OOP(面向对象编程)是对真实世界的一种抽象思维方式,可以在更高的层次上对所 ...
- web应用/http协议/web框架
一.web应用 Web应用程序是一种可以通过Web访问的应用程序,程序的最大好处是用户很容易访问应用程序,用户只需要有浏览器即可,不需要再安装其他软件.应用程序有两种模式C/S.B/S.C/S是客户端 ...
- ELK服务基础
官方文档 什么是ELK? 通俗来讲,ELK是由Elasticsearch.Logstash.Kibana三个开源软件组成的一个组合体,这三个软件当中,每个软件用于完成不同的功能,ELK又称为ELK s ...
- leetcode之Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...
- Python开发【杂货铺】:写code经常记不住的事儿
1.添加系统环境变量: 每次写程序,把程序路径添加到环境变量中时,总是磕磕绊绊忘一些,搞得总是从之前的程序里直接copy # 程序目录添加到系统环境变量 import os import sys im ...
- ovn-sb 摘要
1.Database Structure Physical network table中包含了和chassis nodes有关的所有信息,包括用于overlay所需的IP地址,支持的tunnel类型以 ...
- python使用tesseract-ocr完成验证码识别
全自动区分计算机和人类的公开图灵测试(Completely Automated Public Turing test to tell Computers and Humans Apart) 简称CAP ...
- mysql 取当前日期对应的周一或周日
select subdate(curdate(),date_format(curdate(),'%w')-1)//获取当前日期在本周的周一 select subdate(curdate(),date_ ...
- docker搭建oracle 11.2.0.3.0
dockerfile 如下: FROM oraclelinux:-slim ARG ORACLE_BASE=/opt/oracle ARG ORACLE_HOME=/opt/oracle/produc ...
- golang 复制对象的正确做法
需求 实际运用种,传参是一对象指针,现在如何最简便地复制一对象? 实现 坑:&* 先拿到值再指针? package main import ( "time" " ...