题意:

用n种颜色染立方体的8个角,问有多少种不同的方法

思路:

共有24种置换,全部写出即可得到结果6x^2+17x^4+x^8

import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
public static void main(String [] args) {
Scanner cin = new Scanner(new BufferedInputStream(System.in));
int T;
T = cin.nextInt();
BigInteger x;
for (int kase = 1; kase <= T; kase++) {
x = cin.nextBigInteger();
BigInteger ans;
BigInteger temp1 = x;
BigInteger temp2 = x;
BigInteger temp3 = x;
temp1 = temp1.multiply(x);
temp1 = temp1.multiply(new BigInteger("6"));
for (int i = 0; i < 3; i++) temp2 = temp2.multiply(x);
temp2 = temp2.multiply(new BigInteger("17"));
for (int i = 0; i < 7; i++) temp3 = temp3.multiply(x);
ans = temp1.add(temp2).add(temp3);
ans = ans.divide(new BigInteger("24"));
System.out.printf("Case %d: ", kase);
String s = ans.toString();
int len = s.length();
if (len <= 15) System.out.println(s);
else {
for (int i = 15; i >= 1; i--) System.out.printf("%c", s.charAt(len-i));
System.out.println();
}
}
cin.close();
}
}