Ways to color a skewed tree such that parent and child have different colors | fast_way is recursive method to calculate power ; Driver Code
< ? php function fastPow ( $ N , $ K ) { if ( $ K == 0 ) return 1 ; $ temp = fastPow ( $ N , $ K / 2 ) ; if ( $ K % 2 == 0 ) return $ temp * $ temp ; else return $ N * $ temp * $ temp ; } function countWays ( $ N , $ K ) { return $ K * fastPow ( $ K - 1 , $ N - 1 ) ; } $ N = 3 ; $ K = 3 ; echo countWays ( $ N , $ K ) ; ? >