Check if a given number can be represented in given a no . of digits in any base | C # program to check if a given number can be represented in given number of digits in any base ; Returns true if ' num ' can be represented usind ' dig ' digits in ' base ' ; Base case ; If there are more than 1 digits left and number is more than base , then remove last digit by doing num / base , reduce the number of digits and recur ; return true of num can be represented in ' dig ' digits in any base from 2 to 32 ; Check for all bases one by one ; Driver code
using System ; class GFG { static bool checkUtil ( int num , int dig , int i ) { if ( dig == 1 && num < i ) return true ; if ( dig > 1 && num >= i ) return checkUtil ( ( num / i ) , -- dig , i ) ; return false ; } static bool check ( int num , int dig ) { for ( int i = 2 ; i <= 32 ; i ++ ) if ( checkUtil ( num , dig , i ) ) return true ; return false ; } public static void Main ( ) { int num = 8 ; int dig = 3 ; if ( check ( num , dig ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }