Minimum positive integer value possible of X for given A and B in X = P * A + Q * B | utility function to calculate gcd ; Driver Program
function gcd ( a , b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } var a = 2 ; var b = 4 ; document . write ( gcd ( a , b ) ) ;