Uva_11255
The key to applying the Burnside theorem is to find the number of immobile solutions for each replacement.
Import Java. Math. biginteger; Import Java. util. vendor; Public Class Main { Static Int Maxd = 50 ; Static Scanner CIN = New Using (system. In ); Static Int N, P, PN; Static Int [] A = New Int [5], B = New Int [5], prime = New Int [Maxd], P = New Int [Maxd]; Static Boolean [] Isprime = New Boolean [Maxd]; Static Biginteger [] FAC = New Biginteger [maxd]; Static Biginteger ans; Public Static Void Main (string [] ARGs) {prepare (); Int T = Cin. nextint (); While (T! = 0 ){ -- T; Init (); solve ();}} Static Void Prepare (){ Int I, J, K = 40 ; FAC [ 0] = FAC [1] = New Biginteger ("1" ); For (I = 2; I <= K; I ++) FAC [I] = FAC [I-1 ]. Multiply (biginteger. valueof (I )); For (I = 0; I <= K; I ++ ) Isprime [I] = True ; P = 0 ; For (I = 2; I <= K; I ++ ) If (Isprime [I]) {Prime [p ++] = I; For (J = I * I; j <= K; j + = I) isprime [I] = False ;}} Static Void Init (){ Int I; n = 0 ; For (I = 0; I <3; I ++ ) {A [I] = Cin. nextint (); n + =A [I];} divide (n );} Static Void Divide ( Int N ){ Int I; PN = 0 ; For (I = 0; I <P & prime [I] * prime [I] <= N; I ++ ) If (N % prime [I] = 0 ) {P [pn ++] =Prime [I]; While (N % prime [I] = 0 ) N /= Prime [I];} If (N> 1 ) P [pn ++] = N ;} Static Int Euler ( Int N ){ Int I, ANS = N; For (I = 0; I <PN; I ++ ) If (N % P [I] = 0 ) Ans = ANS/P [I] * (p [I]-1 ); Return Ans ;} Static Void Solve () {ans = New Biginteger ("0" ); DFS ( 0, 1 , N ); If (N % 2 = 1 ){ For ( Int I = 0; I <3; I ++ ){ For ( Int J = 0; j <3; j ++ ) B [J] = A [J]; -- B [I]; If (B [I] <0 ) Continue ; Ans = Ans. Add (calculate (2 ). Multiply (biginteger. valueof (N )));}} Else { For ( Int I = 0; I <3; I ++ ) B [I] = A [I]; ans = Ans. Add (calculate (2). Multiply (biginteger. valueof (n/2 ))); For ( Int I = 0; I <3; I ++ ) For ( Int J = 0; j <3; j ++ ){ For ( Int K = 0; k <3; k ++ ) B [k] = A [k]; -- B [I]; -- B [J]; If (B [I] <0 | B [J] <0) Continue ; Ans = Ans. Add (calculate (2). Multiply (biginteger. valueof (n/2 );} Ans = Ans. Divide (biginteger. valueof (2 * N); system. Out. println (ANS );} Static Biginteger calculate ( Int M ){ Int I, n = 0 ; Biginteger ans = New Biginteger ("1"); For (I = 0; I <3; I ++ ){ If (B [I] % m! = 0 ) Return Biginteger. Zero; B [I] /= M; n + = B [I];} For (I = 0; I <3; I ++ ) {Ans = Ans. Multiply (comb (n, B [I]); n -=B [I];} Return Ans ;} Static Void DFS ( Int Cur, Int V, Int X ){ Int I, CNT = 0, T = 1 ; If (Cur = PN ){ For (I = 0; I <3; I ++) B [I] = A [I]; ans = Ans. Add (calculate (N/V). Multiply (biginteger. valueof (Euler (N/ V )))); Return ;} While (X % P [cur] = 0 ){ ++ CNT; x /= P [cur];} For (I = 0; I <= CNT; I ++ ) {DFS (cur + 1, V *T, x); t * = P [cur] ;}} Static Biginteger comb ( Int N, Int M ){ Return FAC [N]. Divide (FAC [m]). Divide (FAC [n- M]) ;}}