Balance pans using given weights that are powers of a number | C # code to check whether scale can be balanced or not ; method returns true if balancing of scale is possible ; baseForm vector will store T 's  representation on base a  in reverse order ; convert T to representation on base a ; make first digit of representation as 0 ; loop over base representation of T ; if any digit is not 0 , 1 , ( a - 1 ) or a then balancing is not possible ; if digit is a or ( a - 1 ) then increase left index ' s ▁ count / ▁ ( case , ▁ when ▁ this ▁ weight ▁ is ▁ transferred ▁ to ▁ T ' s side ) ; if representation is processed then balancing is possible ; Driver code
using System ; using System . Collections . Generic ; class GFG { static bool isBalancePossible ( int T , int a ) { List < int > baseForm = new List < int > ( ) ; int s = 0 ; while ( T > 0 ) { baseForm . Add ( T % a ) ; T /= a ; s ++ ; } baseForm . Add ( 0 ) ; for ( int i = 0 ; i < s ; i ++ ) { if ( baseForm [ i ] != 0 && baseForm [ i ] != 1 && baseForm [ i ] != ( a - 1 ) && baseForm [ i ] != a ) { return false ; } if ( baseForm [ i ] == a || baseForm [ i ] == ( a - 1 ) ) { baseForm . Insert ( i + 1 , baseForm [ i + 1 ] + 1 ) ; } } return true ; } public static void Main ( ) { int T = 11 ; int a = 4 ; bool balancePossible = isBalancePossible ( T , a ) ; if ( balancePossible ) { Console . WriteLine ( " Balance ▁ is ▁ possible " ) ; } else { Console . WriteLine ( " Balance ▁ is ▁ not ▁ possible " ) ; } } }