Orbit counting theorem or Burnside 's Lemma | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countDistinctWays ( int N , int M ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int K = __gcd ( i , N ) ; ans += pow ( M , K ) ; } ans /= N ; cout << ans << endl ; } int main ( ) { int N = 4 , M = 3 ; countDistinctWays ( N , M ) ; return 0 ; }