前言
今天早上由于剩下的非权限题实在是太难了。。
于是学了一下新东西续命。。
题解
直接Prufer序列排列组合就好了。。
注意各种0的情况
CODE:
#include<cstdio>
#include<cstring>
typedef long long LL;
const LL N=155;
LL n;
LL a[N];
LL pri[N];
LL tot;
LL cnt[N];
bool ok[N];//这个是不是
void get_pri()
{
memset(ok,true,sizeof(ok));
for (LL u=2;u<N;u++)
{
if (ok[u]==true) pri[++tot]=u;
for (LL i=1;i<=tot;i++)
{
LL x=pri[i];
if (x*u>=N) break;
ok[x*u]=false;
if (u%x==0) break;
}
}
}
void add (LL x,LL y)
{
for (LL u=1;u<=tot;u++)
{
while (x%pri[u]==0)
{
x/=pri[u];
cnt[u]+=y;
}
}
}
LL get (LL x,LL y)
{
for (LL u=2;u<=x;u++)
add(u,y);
}
int main()
{
memset(cnt,0,sizeof(cnt));
get_pri();
scanf("%lld",&n);
if (n==1)
{
LL x;
scanf("%lld",&x);
if (x==0) printf("1\n");
else printf("0\n");
return 0;
}
get(n-2,1);
LL sum=0;
for (LL u=1;u<=n;u++)
{
scanf("%lld",&a[u]);
if (a[u]==0)
{
printf("0\n");
return 0;
}
sum=sum+a[u];
get(a[u]-1,-1);
}
if (sum!=(n-1)*2) {printf("0\n");return 0;}
LL ans=1;
for (LL u=1;u<=tot;u++)
for (LL i=1;i<=cnt[u];i++)
ans=ans*pri[u];
printf("%lld\n",ans);
return 0;
}