题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3547
题目大意:求用$C$种颜色给立方体的8个顶点染色的本质不同的方法。两种方法本质不同即不能通过旋转立方体使得两个立方体的染色情况一致。
简要题解:首先可以得到有24种组合旋转方式。根据Polya定理以及群论中的拉格朗日定理,然后再自己多想一想,就可以得到:$Ans=\frac{x^8+Ax^4+Bx^2+Cx}{24}$,可知有3个未知数,然后样例正好有3组数据,所以可以解方程解得$A=17,B=6,C=0$。注意第三个数据是模了$10^{15}$次方的,但是显然$112^4$的四次方并不会超过$10^{15}$,所以也可以拿来使用。最后直接高精度就可以了。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define K 10
#define D 15 const int T[] = {, , , , };
int Case, n; struct Big
{
int len, num[];
Big () {len = ; memset(num, , sizeof(num));}
void init(int k)
{
len = ;
memset(num, , sizeof(num));
for (; k; k /= K)
num[++ len] = k % K;
len = max(len, );
}
void Add(Big a)
{
len = max(len, a.len);
for (int i = ; i <= len; i ++)
num[i] += a.num[i];
for (int i = ; i < len; i ++)
if (num[i] >= K)
{
num[i + ] ++;
num[i] -= K;
}
if (num[len] >= K)
{
num[len + ] = ;
num[len ++] -= K;
}
}
void Times(Big a)
{
Big b;
b.len = len + a.len - ;
for (int i = ; i <= len; i ++)
for (int j = ; j <= a.len; j ++)
b.num[i + j - ] += num[i] * a.num[j];
for (int i = ; i < b.len; i ++)
if (b.num[i] >= K)
{
b.num[i + ] += b.num[i] / K;
b.num[i] %= K;
}
while (b.num[b.len] >= K)
{
b.num[b.len + ] += b.num[b.len] / K;
b.num[b.len ++] %= K;
}
len = b.len;
for (int i = ; i <= len; i ++)
num[i] = b.num[i];
}
void Multi(int k)
{
for (int i = ; i <= len; i ++)
num[i] *= k;
for (int i = ; i < len; i ++)
if (num[i] >= K)
{
num[i + ] += num[i] / K;
num[i] %= K;
}
while (num[len] >= K)
{
num[len + ] += num[len] / K;
num[len ++] %= K;
}
}
void Divide(int k)
{
for (int i = len; i >= ; i --)
{
if (i > ) num[i - ] += (num[i] % k) * K;
num[i] /= k;
}
for (; !num[len] && len > ; len --) ;
}
void out()
{
for (int i = min(D, len); i; i --)
printf("%d", num[i]);
puts("");
}
}A[], Ans; int main()
{
scanf("%d", &Case);
for (int Test = ; Test <= Case; Test ++)
{
scanf("%d", &n);
A[].init(n), Ans.init();
for (int i = ; i <= ; i ++)
{
A[i] = A[i - ];
A[i].Times(A[i - ]);
A[i].Multi(T[i]);
Ans.Add(A[i]);
A[i].Divide(T[i]);
}
Ans.Divide();
printf("Case %d: ", Test);
Ans.out();
}
return ;
}
HDOJ 3547
#include <cstdio>
typedef long long LL;
#define Mod 10000000000000000LL const int Base[] = {, , , };
const LL Ans[] = {0LL, 23LL, 296LL, 2675058176LL}; struct Frac
{
LL fz, fm;
Frac (LL _fz = 0LL, LL _fm = 0LL) {fz = _fz, fm = _fm;}
LL Abs(LL x)
{
return x > ? x : -x;
}
LL gcd(LL x, LL y)
{
return !y ? x : gcd(y, x % y);
}
void Simplify()
{
LL d = gcd(Abs(fz), Abs(fm));
fz /= d, fm /= d;
if (fm < ) fm = -fm, fz = -fz;
}
Frac operator + (const Frac a)
{
Frac b;
b.fz = fz * a.fm + fm * a.fz;
b.fm = fm * a.fm;
b.Simplify();
return b;
}
Frac operator - (const Frac a)
{
Frac b;
b.fz = fz * a.fm - fm * a.fz;
b.fm = fm * a.fm;
b.Simplify();
return b;
}
Frac operator * (const Frac a)
{
Frac b;
b.fz = fz * a.fz;
b.fm = fm * a.fm;
b.Simplify();
return b;
}
Frac operator / (const Frac a)
{
Frac b;
b.fz = fz * a.fm;
b.fm = fm * a.fz;
b.Simplify();
return b;
}
void out()
{
printf("%lld/%lld\n", fz, fm);
}
}X[][], Y[]; inline void Gauss()
{
for (int i = ; i < ; i ++)
for (int j = i + ; j <= ; j ++)
{
Frac t = X[j][i] / X[i][i];
for (int k = i; k <= ; k ++)
X[j][k] = X[j][k] - X[i][k] * t;
Y[j] = Y[j] - Y[i] * t;
}
for (int i = ; i; i --)
{
Frac sum;
sum.fz = 0LL, sum.fm = 1LL;
for (int j = i + ; j <= ; j ++)
sum = sum + X[i][j] * Y[j];
Y[i] = (Y[i] - sum) / X[i][i];
}
} int main()
{
for (int i = ; i <= ; i ++)
{
for (int j = ; j; j --)
{
if (j == ) X[i][j].fz = Base[i];
else X[i][j].fz = X[i][j + ].fz * X[i][j + ].fz;
X[i][j].fm = 1LL;
}
Y[i].fz = Ans[i], Y[i].fm = 1LL;
}
Gauss();
for (int i = ; i <= ; i ++)
Y[i].out();
return ;
}
HDOJ 3547 (Gauss)