Count of distinct values till C formed by adding or subtracting A , B , or 0 any number of times | C # program for the above approach ; 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
using System ; class GFG { static int gcd ( int A , int B ) { if ( B == 0 ) return A ; else return gcd ( B , A % B ) ; } static int getDistinctValues ( int A , int B , int C ) { int g = gcd ( A , B ) ; int num_values = C / g ; return num_values ; } static void Main ( ) { int A = 2 ; int B = 3 ; int C = 10 ; Console . Write ( getDistinctValues ( A , B , C ) ) ; } }