Smallest power of 2 consisting of N digits | Java Program of the above approach ; Function to return smallest power of 2 consisting of N digits ; calculate log2 N indirectly using log ( ) method ; Driver Code
class GFG { static int smallestNum ( int n ) { double power = log2 ( 10 ) ; return ( int ) Math . ceil ( ( n - 1 ) * power ) ; } static double log2 ( int N ) { return ( Math . log ( N ) / Math . log ( 2 ) ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( smallestNum ( n ) ) ; } }