DIY Cube
Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 207 Accepted Submission(s): 111
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
Author
HyperHexagon
Source
HyperHexagon‘s Summer Gift (Original tasks)
Recommend
zhengfeng
polya定理的应用,需要加高精最后输出。如果想不到,你可以用置换群乘法让计算机代替你去算每种操作的循环节,我这里是已经在纸上算好的了。
假设有x种颜色。
对于一个cube有四种大置换:
1:固定对立的面旋转,共有3对对立面:
可得旋转90°与旋转270°互为逆操作,都有两个循环节,共有 3*2*x^2个不动点;
旋转180°有四个循环节,共有3*1*x^4个不动点;
共有3*2+3*1=9种置换。
2:固定对立的边旋转,共有6对对立边:
只可旋转180°,有四个循环节,共有6*1*x^4个不动点;
共有6种置换。
3:固定对立的角旋转,共有4对对立的角:
旋转120°与旋转270°互为逆操作,都有四个循环节,共有4*2*x^4 个不动点。
共4*2=8种置换。
4:不动:
有8个循环节,有X^8个不动点。
共1种置换。
所以共有24种置换。
共有x^8+17*x^4+6*x^2个不动点。
由L=1/|G| *Σ(D(ai))得:
等价类L=1/24*(x^8+17*x^4+6*x^2);
由于保留后15位,数字也过大,用大数与小数的高精度去处理。
下面给出代码:
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #define clr(x) memset(x,0,sizeof(x)) 5 #define cop(x,y) memcpy(x,y,sizeof(y)) 6 #define LL long long 7 #define lim 10 8 using namespace std; 9 LL ans[1000]; 10 LL xpow[1000];//x的幂 11 LL dv[1000]; 12 int dd[5]={0,6,17,0,1}; 13 // x^(i/2)的系数 14 void add(LL *a,LL *b);//高精加 15 void mul(LL *a,int b);//高精乘 16 void div(LL *a,int b);//高精除 17 int main() 18 { 19 int T,x; 20 scanf("%d",&T); 21 for(int t=1;t<=T;t++) 22 { 23 scanf("%d",&x); 24 printf("Case %d: ",t); 25 clr(ans); 26 clr(xpow); 27 xpow[0]=1; 28 for(int i=1;i<=8;i++) 29 { 30 mul(xpow,x); 31 if(i%2==0) 32 { 33 cop(dv,xpow); 34 mul(dv,dd[i/2]); 35 add(ans,dv); 36 } 37 } 38 div(ans,24); 39 int v=14; 40 while(ans[v]==0) v--; 41 for(int i=v;i>=0;i--) 42 printf("%d",ans[i]); 43 printf("\n"); 44 } 45 return 0; 46 } 47 void mul(LL *a,int b) 48 { 49 LL ret=0; 50 for(int i=0;a[i]!=0 || ret!=0;i++) 51 { 52 ret=ret/lim+a[i]*b; 53 a[i]=ret%lim; 54 } 55 return ; 56 } 57 void add(LL *a,LL *b) 58 { 59 LL ret=0; 60 for(int i=0;a[i]!=0 || b[i]!=0 || ret!=0;i++) 61 { 62 ret=ret/lim+a[i]+b[i]; 63 a[i]=ret%lim; 64 } 65 return ; 66 67 } 68 void div(LL *a,int b) 69 { 70 LL ret=0; 71 int v=0; 72 while(a[v]>0) 73 v++; 74 v--; 75 for(int i=v;i>=0;i--) 76 { 77 ret=ret*lim+a[i]; 78 a[i]=ret/b; 79 ret%=b; 80 } 81 return ; 82 }