Minimum number of coins that can generate all the values in the given range | C # implementation of the above approach ; Function to return the count of minimum coins required ; To store the required sequence ; Creating list of the sum of all previous bit values including that bit value ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int findCount ( int N ) { List < int > list = new List < int > ( ) ; int sum = 0 ; int i ; for ( i = 0 ; i < 20 ; i ++ ) { sum += ( int ) Math . Pow ( 2 , i ) ; list . Add ( sum ) ; } for ( i = 0 ; i < 20 ; i ++ ) { if ( ( int ) list [ i ] >= N ) return ( i + 1 ) ; } return 0 ; } public static void Main ( String [ ] args ) { int N = 10 ; Console . WriteLine ( findCount ( N ) ) ; } }