标签:force 统计 ++ piped space ack namespace The div
大意: 给定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 (计数)
标签:force 统计 ++ piped space ack namespace The div
原文地址:https://www.cnblogs.com/uid001/p/10480583.html