Count of distinct values till C formed by adding or subtracting A , B , or 0 any number of times | Function to calculate gcd ; Function to find number of possible final values ; Find the gcd of two numbers ; Calculate number of distinct values ; Return values ; Driver Code
function gcd ( A , B ) { if ( B == 0 ) return A ; else return gcd ( B , A % B ) ; } function getDistinctValues ( A , B , C ) { let g = gcd ( A , B ) ; let num_values = C / g ; return num_values ; } let A = 2 ; let B = 3 ; let C = 10 ; document . write ( getDistinctValues ( A , B , C ) ) ;