DIY Cube
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 584 Accepted Submission(s): 284
Problem Description
Mr. D is interesting in combinatorial enumeration. Now he want to find out the number of ways on painting the vertexes of a cube. Suppose there are C different colors and two paintings are considered the same if they can transform from one to another by rotation.
Input
There are multiple test cases in the input, the first line of input contains an integer denoting the number of test cases.
For each test case, there are only one integer C, denoting the number of colors. (1 <= C <= 1000000000)
Output
For each test case, output the the number of painting ways. And if the number is equal or larger than 1015, output the last 15 digits.
Sample Input
3 1 2 112
Sample Output
Case 1: 1 Case 2: 23 Case 3: 031651434916928 /* * 题意:用n中颜色涂一个正方体的八个顶点,求有多少种方法。 假设得到的结果大于等于10^15,则输出后15位就可以。 思路:Ploya定理啊,是组合数学课本上的原题。相应于四种不同类型的旋转,1:不动,即恒等旋转有1个;2:绕三对对立面的中心旋转,有旋转90度,旋转180度,旋转270度,分别有3个;3:绕对边终点连线旋转,有6个。4:绕对角点旋转,有旋转120度和旋转240度,分别有4个。因此共同拥有24个对称。最后能够转化成公式(k^8 + 17*k^4 + 6 * k^2)/ 24 。 因为涉及到了大数,所以这道题我使用java写的,刚学java。 看着大神的分析,写了写试试。java单词好多。 */import java.util.*; import java.math.*; import java.math.BigInteger; public class Main { public static void main(String[] args){ int i,j; BigInteger sum,k,temp; temp= new BigInteger ("1000000000000000"); Scanner in=new Scanner(System.in); int t=in.nextInt(); for(i=1;i<=t;i++){ sum= BigInteger.ZERO; k=in.nextBigInteger(); sum=sum.add(k.pow(8)); sum=sum.add(k.pow(4).multiply(BigInteger.valueOf(17))); sum=sum.add(k.pow(2).multiply(BigInteger.valueOf(6))); sum=sum.divide(BigInteger.valueOf(24)); System.out.print("Case "+i+": "); if(sum.compareTo(temp) > 0){ sum= sum.mod(temp); for(j=sum.toString().length(); j<15;j++){ System.out.print(0); } } System.out.println(sum); } } }