Frobenius coin problem | C ++ program to find the largest number that cannot be formed from given two coins ; Utility function to find gcd ; Function to print the desired output ; Solution doesn 't exist   if GCD is not 1 ; Else apply the formula ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int gcd ( int a , int b ) { int c ; while ( a != 0 ) { c = a ; a = b % a ; b = c ; } return b ; } void forbenius ( int X , int Y ) { if ( gcd ( X , Y ) != 1 ) { cout << " NA STRNEWLINE " ; return ; } int A = ( X * Y ) - ( X + Y ) ; int N = ( X - 1 ) * ( Y - 1 ) / 2 ; cout << " Largest ▁ Amount ▁ = ▁ " << A << endl ; cout << " Total ▁ Count ▁ = ▁ " << N << endl ; } int main ( ) { int X = 2 , Y = 5 ; forbenius ( X , Y ) ; X = 5 , Y = 10 ; cout << endl ; forbenius ( X , Y ) ; return 0 ; }