Minimize coins required to obtain all possible values up to N | Java program to implement the above approach ; Function to find minimum count of { 1 , 2 , 5 } valued coins required to make a change of all values in the range [ 1 , N ] ; Number of 5 valueds coins required ; Number of 1 valued coins required ; Number of 2 valued coins required ; Driver Code
import java . util . * ; class GFG { static void find ( int N ) { int T , F , O ; F = ( int ) ( ( N - 4 ) / 5 ) ; if ( ( ( N - 5 * F ) % 2 ) == 0 ) { O = 2 ; } else { O = 1 ; } T = ( int ) Math . floor ( ( N - 5 * F - O ) / 2 ) ; System . out . println ( " Count ▁ of ▁ 5 ▁ valueds ▁ coins : ▁ " + F ) ; System . out . println ( " Count ▁ of ▁ 2 ▁ valueds ▁ coins : ▁ " + T ) ; System . out . println ( " Count ▁ of ▁ 1 ▁ valueds ▁ coins : ▁ " + O ) ; } public static void main ( String args [ ] ) { int N = 8 ; find ( N ) ; } }