Orbit counting theorem or Burnside 's Lemma | Java program for implementing the Orbit counting theorem or Burnside 's Lemma ; Function to find result using Orbit counting theorem or Burnside 's Lemma ; According to Burnside 's Lemma  calculate distinct ways for each  rotation ; Find GCD ; Divide By N ; Print the distinct ways ; Driver Code ; N stones and M colors ; Function call
class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static void countDistinctWays ( int N , int M ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int K = gcd ( i , N ) ; ans += Math . pow ( M , K ) ; } ans /= N ; System . out . print ( ans ) ; } public static void main ( String [ ] args ) { int N = 4 , M = 3 ; countDistinctWays ( N , M ) ; } }