CF963
CF963C
首先假设横向被分成p块纵向被分成q块,\(C_i\)为横向长度为\(i\)的方块个数,\(D_i\)为纵向长度为\(i\)的方块个数
\(p\times q=\)总块数T,q要是所有\(C_i\)的gcd的因数,p是所有\(D_i\)的gcd的因数
然后随手一交发现不对,比如\(1\times 1=2, 1\times 2=1, 2\times 1=1, 2\times 2=2\)
设长x宽y的块有\(w_{x,y}\)个,这就要求对于制定的长x\(w_{x,1}:w_{x,2}:\cdot \cdot \cdot :w{x,k}=D_1:D_2:\cdot \cdot \cdot :D{k}\)
冷静分析一下就是\(\frac{w_{x,y}}{C_x}=\frac{D_y}{T}\)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cmath>
#define LL long long
#define LD long double
using namespace std;
const int M = 1000001;
map<LL,LL>mg,mh;
LL T,n,m,k,x,y,c,G,H,res,a[M],b[M],d[M];
LL gcd(LL x,LL y)
{
if(!y) return x;
return gcd(y,x%y);
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x>>y>>c;
if(mg.find(x)==mg.end()) mg[x]=0;
if(mh.find(y)==mh.end()) mh[y]=0;
mg[x]+=c; mh[y]+=c;
T+=c;
a[i]=x, b[i]=y, d[i]=c;
}
map<LL,LL>::iterator it;
it=mg.begin();
while(it!=mg.end()) G=gcd(G,it->second),it++;
it=mh.begin();
while(it!=mh.end()) H=gcd(H,it->second),it++;
for(int i=1;i<=n;i++)
{
if(fabs((LD)d[i]/mg[a[i]]-(LD)mh[b[i]]/T)>1e-10)
{
printf("0");
return 0;
}
}
if(H<G) swap(H,G);
LL k=sqrt(G);
for(int i=1;i<=k;i++) if(G%i==0)
{
if(T%i==0 && H%(T/i)==0) res+=1ll;
if(i*i!=G && T%(G/i)==0 && H%(T/(G/i))==0) res+=1ll;
}
cout<<res;
}