codeparrot/xlcost-text-to-code huggingface dataset:
Segmented Sieve | This functions finds all primes smaller than ' limit ' using simple sieve of eratosthenes . ; Create a boolean array " mark [ 0 . . limit - 1 ] " and initialize all entries of it as true . A value in mark [ p ] will finally be false if ' p ' is Not a prime , else true . ; One by one traverse all numbers so that their multiples can be marked as composite . ; If p is not changed , then it is a prime ; Update all multiples of p ; Print all prime numbers and store them in prime
static void simpleSieve ( int limit ) { bool [ ] mark = new bool [ limit ] ; Array . Fill ( mark , true ) ; for ( int p = 2 ; p * p < limit ; p ++ ) { if ( mark [ p ] == true ) { for ( int i = p * p ; i < limit ; i += p ) mark [ i ] = false ; } } for ( int p = 2 ; p < limit ; p ++ ) if ( mark [ p ] == true ) Console . Write ( p + " ▁ " ) ; }
Segmented Sieve | C # program to print print all primes smaller than n using segmented sieve ; This methid finds all primes smaller than ' limit ' using simple sieve of eratosthenes . It also stores found primes in vector prime [ ] ; Create a boolean array " mark [ 0 . . n - 1 ] " and initialize all entries of it as true . A value in mark [ p ] will finally be false if ' p ' is Not a prime , else true . ; If p is not changed , then it is a prime ; Update all multiples of p ; Print all prime numbers and store them in prime ; Prints all prime numbers smaller than ' n ' ; Compute all primes smaller than or equal to square root of n using simple sieve ; Divide the range [ 0. . n - 1 ] in different segments We have chosen segment size as sqrt ( n ) . ; While all segments of range [ 0. . n - 1 ] are not processed , process one segment at a time ; To mark primes in current range . A value in mark [ i ] will finally be false if ' i - low ' is Not a prime , else true . ; Use the found primes by simpleSieve ( ) to find primes in current range ; Find the minimum number in [ low . . high ] that is a multiple of prime . get ( i ) ( divisible by prime . get ( i ) ) For example , if low is 31 and prime . get ( i ) is 3 , we start with 33. ; Mark multiples of prime . get ( i ) in [ low . . high ] : We are marking j - low for j , i . e . each number in range [ low , high ] is mapped to [ 0 , high - low ] so if range is [ 50 , 100 ] marking 50 corresponds to marking 0 , marking 51 corresponds to 1 and so on . In this way we need to allocate space only for range ; Numbers which are not marked as false are prime ; Update low and high for next segment ; Driver code
using System ; using System . Collections ; class GFG { static void simpleSieve ( int limit , ArrayList prime ) { bool [ ] mark = new bool [ limit + 1 ] ; for ( int i = 0 ; i < mark . Length ; i ++ ) mark [ i ] = true ; for ( int p = 2 ; p * p < limit ; p ++ ) { if ( mark [ p ] == true ) { for ( int i = p * p ; i < limit ; i += p ) mark [ i ] = false ; } } for ( int p = 2 ; p < limit ; p ++ ) { if ( mark [ p ] == true ) { prime . Add ( p ) ; Console . Write ( p + " ▁ " ) ; } } } static void segmentedSieve ( int n ) { int limit = ( int ) ( Math . Floor ( Math . Sqrt ( n ) ) + 1 ) ; ArrayList prime = new ArrayList ( ) ; simpleSieve ( limit , prime ) ; int low = limit ; int high = 2 * limit ; while ( low < n ) { if ( high >= n ) high = n ; bool [ ] mark = new bool [ limit + 1 ] ; for ( int i = 0 ; i < mark . Length ; i ++ ) mark [ i ] = true ; for ( int i = 0 ; i < prime . Count ; i ++ ) { int loLim = ( ( int ) Math . Floor ( ( double ) ( low / ( int ) prime [ i ] ) ) * ( int ) prime [ i ] ) ; if ( loLim < low ) loLim += ( int ) prime [ i ] ; for ( int j = loLim ; j < high ; j += ( int ) prime [ i ] ) mark [ j - low ] = false ; } for ( int i = low ; i < high ; i ++ ) if ( mark [ i - low ] == true ) Console . Write ( i + " ▁ " ) ; low = low + limit ; high = high + limit ; } } static void Main ( ) { int n = 100 ; Console . WriteLine ( " Primes ▁ smaller ▁ than ▁ " + n + " : " ) ; segmentedSieve ( n ) ; } }
Find the smallest twins in given range | C # program to find the smallest twin in given range ; Create a boolean array " prime [ 0 . . high ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; Look for the smallest twin ; If p is not marked , then it is a prime ; Update all multiples of p ; Now print the smallest twin in range ; Driver program
using System ; public class GFG { static void printTwins ( int low , int high ) { bool [ ] prime = new bool [ high + 1 ] ; bool twin = false ; for ( int i = 0 ; i < prime . Length ; i ++ ) { prime [ i ] = true ; } prime [ 0 ] = prime [ 1 ] = false ; for ( int p = 2 ; p <= Math . Floor ( Math . Sqrt ( high ) ) + 1 ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= high ; i += p ) { prime [ i ] = false ; } } } for ( int i = low ; i <= high ; i ++ ) { if ( prime [ i ] && prime [ i + 2 ] ) { int a = i + 2 ; Console . Write ( " Smallest ▁ twins ▁ in ▁ given ▁ range : ▁ ( " + i + " , ▁ " + a + " ) " ) ; twin = true ; break ; } } if ( twin == false ) { Console . WriteLine ( " No ▁ such ▁ pair ▁ exists " ) ; } } public static void Main ( ) { printTwins ( 10 , 100 ) ; } }
Check if a given number is Fancy | C # program to find if a given number is fancy or not ; To store mappings of fancy pair characters . For example 6 is paired with 9 and 9 is paired with 6. ; Find number of digits in given number ; Traverse from both ends , and compare characters one by one ; If current characters at both ends are not fancy pairs ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static bool isFancy ( String num ) { Dictionary < char , char > fp = new Dictionary < char , char > ( ) ; fp . Add ( '0' , '0' ) ; fp . Add ( '1' , '1' ) ; fp . Add ( '6' , '9' ) ; fp . Add ( '8' , '8' ) ; fp . Add ( '9' , '6' ) ; int n = num . Length ; int l = 0 , r = n - 1 ; while ( l <= r ) { if ( ! fp . ContainsKey ( num [ l ] ) fp [ num [ l ] ] != num [ r ] ) return false ; l ++ ; r -- ; } return true ; } public static void Main ( String [ ] args ) { String str = "9088806" ; if ( isFancy ( str ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Find Next Sparse Number | C # program to find next sparse number ; Find binary representation of x and store it in bin . get ( ] . bin . get ( 0 ] contains least significant bit ( LSB ) , next bit is in bin . get ( 1 ] , and so on . ; There my be extra bit in result , so add one extra bit ; The position till which all bits are finalized ; Start from second bit ( next to LSB ) ; If current bit and its previous bit are 1 , but next bit is not 1. ; Make the next bit 1 ; Make all bits before current bit as 0 to make sure that we get the smallest next number ; Store position of the bit set so that this bit and bits before it are not changed next time . ; Find decimal equivalent of modified bin . get ( ] ; Driver program
using System ; using System . Collections ; class GFG { static int nextSparse ( int x ) { ArrayList bin = new ArrayList ( ) ; while ( x != 0 ) { bin . Add ( x & 1 ) ; x >>= 1 ; } bin . Add ( 0 ) ; int last_final = 0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( ( int ) bin [ i ] == 1 && ( int ) bin [ i - 1 ] == 1 && ( int ) bin [ i + 1 ] != 1 ) { bin [ i + 1 ] = 1 ; for ( int j = i ; j >= last_final ; j -- ) bin [ j ] = 0 ; last_final = i + 1 ; } } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans += ( int ) bin [ i ] * ( 1 << i ) ; return ans ; } static void Main ( ) { int x = 38 ; Console . WriteLine ( " Next ▁ Sparse ▁ Number ▁ is ▁ " + nextSparse ( x ) ) ; } }
Count number of subsets of a set with GCD equal to a given number | C # program to count number of subsets with given GCDs ; n is size of [ ] arr and m is sizeof gcd [ ] ; Map to store frequency of array elements ; Map to store number of subsets with given gcd ; Initialize maximum element . Assumption : all array elements are positive . ; Find maximum element in array and fill frequency map . ; Run a loop from max element to 1 to find subsets with all gcds ; Run a loop for all multiples of i ; Sum the frequencies of every element which is a multiple of i ; Excluding those subsets which have gcd > i but not i i . e . which have gcd as multiple of i in the subset for ex : { 2 , 3 , 4 } considering i = 2 and subset we need to exclude are those having gcd as 4 ; Number of subsets with GCD equal to ' i ' is Math . Pow ( 2 , add ) - 1 - sub ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void ccountSubsets ( int [ ] arr , int n , int [ ] gcd , int m ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; Dictionary < int , int > subsets = new Dictionary < int , int > ( ) ; int arrMax = 0 ; for ( int i = 0 ; i < n ; i ++ ) { arrMax = Math . Max ( arrMax , arr [ i ] ) ; if ( freq . ContainsKey ( arr [ i ] ) ) { freq . Add ( arr [ i ] , freq [ arr [ i ] ] + 1 ) ; } else { freq . Add ( arr [ i ] , 1 ) ; } } for ( int i = arrMax ; i >= 1 ; i -- ) { int sub = 0 ; int add = 0 ; if ( freq . ContainsKey ( i ) ) add = freq [ i ] ; for ( int j = 2 ; j * i <= arrMax ; j ++ ) { if ( freq . ContainsKey ( i * j ) ) add += freq [ j * i ] ; sub += subsets [ j * i ] ; } subsets . Add ( i , ( 1 << add ) - 1 - sub ) ; } for ( int i = 0 ; i < m ; i ++ ) Console . Write ( " Number ▁ of ▁ subsets ▁ with ▁ gcd ▁ " + gcd [ i ] + " ▁ is ▁ " + subsets [ gcd [ i ] ] + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] gcd = { 2 , 3 } ; int [ ] arr = { 9 , 6 , 2 } ; int n = arr . Length ; int m = gcd . Length ; ccountSubsets ( arr , n , gcd , m ) ; } }
Sum of bit differences among all pairs | C # program to compute sum of pairwise bit differences ; traverse over all bits ; count number of elements with i 'th bit set ; Add " count ▁ * ▁ ( n ▁ - ▁ count ) ▁ * ▁ 2" to the answer ; Driver Code
using System ; class GFG { static int sumBitDifferences ( int [ ] arr , int n ) { for ( int i = 0 ; i < 32 ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < n ; j ++ ) if ( ( arr [ j ] & ( 1 << i ) ) == 0 ) count ++ ; ans += ( count * ( n - count ) * 2 ) ; } return ans ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , 5 } ; int n = arr . Length ; Console . Write ( sumBitDifferences ( arr , n ) ) ; } }
Print all non | C # program to generate all non - increasing sequences of sum equals to x ; Utility function to print array arr [ 0. . n - 1 ] ; Recursive Function to generate all non - increasing sequences with sum x arr [ ] -- > Elements of current sequence curr_sum -- > Current Sum curr_idx -- > Current index in arr [ ] ; If current sum is equal to x , then we found a sequence ; Try placing all numbers from 1 to x - curr_sum at current index ; The placed number must also be smaller than previously placed numbers and it may be equal to the previous stored value , i . e . , arr [ curr_idx - 1 ] if there exists a previous number ; Place number at curr_idx ; Recur ; Try next number ; A wrapper over generateUtil ( ) ; Array to store sequences on by one ; Driver program
using System ; class GFG { static void printArr ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] ) ; Console . WriteLine ( ) ; } static void generateUtil ( int x , int [ ] arr , int curr_sum , int curr_idx ) { if ( curr_sum == x ) { printArr ( arr , curr_idx ) ; return ; } int num = 1 ; while ( num <= x - curr_sum && ( curr_idx == 0 num <= arr [ curr_idx - 1 ] ) ) { arr [ curr_idx ] = num ; generateUtil ( x , arr , curr_sum + num , curr_idx + 1 ) ; num ++ ; } } static void generate ( int x ) { int [ ] arr = new int [ x ] ; generateUtil ( x , arr , 0 , 0 ) ; } public static void Main ( ) { int x = 5 ; generate ( x ) ; } }
Perfect Number | C # program to check if a given number is perfect or not ; Returns true if n is perfect ; To store sum of divisors ; Find all divisors and add them ; If sum of divisors is equal to n , then n is a perfect number ; Driver program
class GFG { static bool isPerfect ( int n ) { int sum = 1 ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i != n ) sum = sum + i + n / i ; else sum = sum + i ; } } if ( sum == n && n != 1 ) return true ; return false ; } static void Main ( ) { System . Console . WriteLine ( " Below ▁ are ▁ all ▁ perfect " + " numbers ▁ till ▁ 10000" ) ; for ( int n = 2 ; n < 10000 ; n ++ ) if ( isPerfect ( n ) ) System . Console . WriteLine ( n + " ▁ is ▁ a ▁ perfect ▁ number " ) ; } }
Check if a given number can be represented in given a no . of digits in any base | C # program to check if a given number can be represented in given number of digits in any base ; Returns true if ' num ' can be represented usind ' dig ' digits in ' base ' ; Base case ; If there are more than 1 digits left and number is more than base , then remove last digit by doing num / base , reduce the number of digits and recur ; return true of num can be represented in ' dig ' digits in any base from 2 to 32 ; Check for all bases one by one ; Driver code
using System ; class GFG { static bool checkUtil ( int num , int dig , int i ) { if ( dig == 1 && num < i ) return true ; if ( dig > 1 && num >= i ) return checkUtil ( ( num / i ) , -- dig , i ) ; return false ; } static bool check ( int num , int dig ) { for ( int i = 2 ; i <= 32 ; i ++ ) if ( checkUtil ( num , dig , i ) ) return true ; return false ; } public static void Main ( ) { int num = 8 ; int dig = 3 ; if ( check ( num , dig ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
How to compute mod of a big number ? | C # program to compute mod of a big number represented as string ; Function to compute num ( mod a ) ; Initialize result ; One by one process all digits of ' num ' ; Driver code
using System ; public class GFG { static int mod ( String num , int a ) { int res = 0 ; for ( int i = 0 ; i < num . Length ; i ++ ) res = ( res * 10 + ( int ) num [ i ] - '0' ) % a ; return res ; } public static void Main ( ) { String num = "12316767678678" ; Console . WriteLine ( mod ( num , 10 ) ) ; } }
Modular multiplicative inverse | C # program to find modular inverse of a under modulo m ; A naive method to find modulor multiplicative inverse of ' a ' under modulo ' m ' ; Driver Code ; Function call
using System ; class GFG { static int modInverse ( int a , int m ) { for ( int x = 1 ; x < m ; x ++ ) if ( ( ( a % m ) * ( x % m ) ) % m == 1 ) return x ; return 1 ; } public static void Main ( ) { int a = 3 , m = 11 ; Console . WriteLine ( modInverse ( a , m ) ) ; } }
Modular multiplicative inverse | Iterative C # program to find modular inverse using extended Euclid algorithm ; Returns modulo inverse of a with respect to m using extended Euclid Algorithm Assumption : a and m are coprimes , i . e . , gcd ( a , m ) = 1 ; q is quotient ; m is remainder now , process same as Euclid 's algo ; Update x and y ; Make x positive ; Driver Code ; Function call
using System ; class GFG { static int modInverse ( int a , int m ) { int m0 = m ; int y = 0 , x = 1 ; if ( m == 1 ) return 0 ; while ( a > 1 ) { int q = a / m ; int t = m ; m = a % m ; a = t ; t = y ; y = x - q * y ; x = t ; } if ( x < 0 ) x += m0 ; return x ; } public static void Main ( ) { int a = 3 , m = 11 ; Console . WriteLine ( " Modular ▁ multiplicative ▁ " + " inverse ▁ is ▁ " + modInverse ( a , m ) ) ; } }
Euler 's Totient Function | A simple C # program to calculate Euler 's Totient Function ; Function to return GCD of a and b ; A simple method to evaluate Euler Totient Function ; Driver code
using System ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int phi ( int n ) { int result = 1 ; for ( int i = 2 ; i < n ; i ++ ) if ( gcd ( i , n ) == 1 ) result ++ ; return result ; } public static void Main ( ) { for ( int n = 1 ; n <= 10 ; n ++ ) Console . WriteLine ( " phi ( " + n + " ) ▁ = ▁ " + phi ( n ) ) ; } }
Euler 's Totient Function | C # program to calculate Euler ' s ▁ Totient ▁ Function ▁ using ▁ Euler ' s product formula ; Initialize result as n ; Consider all prime factors of n and for every prime factor p , multiply result with ( 1 - 1 / p ) ; Check if p is a prime factor . ; If yes , then update n and result ; If n has a prime factor greater than sqrt ( n ) ( There can be at - most one such prime factor ) ; Driver Code
using System ; class GFG { static int phi ( int n ) { float result = n ; for ( int p = 2 ; p * p <= n ; ++ p ) { if ( n % p == 0 ) { while ( n % p == 0 ) n /= p ; result *= ( float ) ( 1.0 - ( 1.0 / ( float ) p ) ) ; } } if ( n > 1 ) result *= ( float ) ( 1.0 - ( 1.0 / ( float ) n ) ) ; return ( int ) result ; } public static void Main ( ) { int n ; for ( n = 1 ; n <= 10 ; n ++ ) Console . WriteLine ( " phi ( " + n + " ) ▁ = ▁ " + phi ( n ) ) ; } }
Program to find remainder without using modulo or % operator | C # implementation of the approach ; Function to return num % divisor without using % ( modulo ) operator ; While divisor is smaller than n , keep subtracting it from num ; Driver code
using System ; class GFG { static int getRemainder ( int num , int divisor ) { while ( num >= divisor ) num -= divisor ; return num ; } public static void Main ( String [ ] args ) { int num = 100 , divisor = 7 ; Console . WriteLine ( getRemainder ( num , divisor ) ) ; } }
Efficient Program to Compute Sum of Series 1 / 1 ! + 1 / 2 ! + 1 / 3 ! + 1 / 4 ! + . . + 1 / n ! | A simple C # program to compute sum of series 1 / 1 ! + 1 / 2 ! + . . + 1 / n ! ; Utility function to find ; A Simple Function to return value of 1 / 1 ! + 1 / 2 ! + . . + 1 / n ! ; Driver program
using System ; class GFG { static int factorial ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res *= i ; return res ; } static double sum ( int n ) { double sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) sum += 1.0 / factorial ( i ) ; return sum ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( sum ( n ) ) ; } }
Find the number of valid parentheses expressions of given length | C # program to find valid paranthesisations of length n The majority of code is taken from method 3 of https : www . geeksforgeeks . org / program - nth - catalan - number / ; Returns value of Binomial Coefficient C ( n , k ) ; Since C ( n , k ) = C ( n , n - k ) ; Calculate value of [ n * ( n - 1 ) * -- - * ( n - k + 1 ) ] / [ k * ( k - 1 ) * -- - * 1 ] ; A Binomial coefficient based function to find nth catalan number in O ( n ) time ; Calculate value of 2 nCn ; return 2 nCn / ( n + 1 ) ; Function to find possible ways to put balanced parenthesis in an expression of length n ; If n is odd , not possible to create any valid parentheses ; Otherwise return n / 2 'th  Catalan Number ; Driver program to test above functions
using System ; class GFG { static long binomialCoeff ( int n , int k ) { long res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static long catalan ( int n ) { long c = binomialCoeff ( 2 * n , n ) ; return c / ( n + 1 ) ; } static long findWays ( int n ) { if ( ( n & 1 ) != 0 ) return 0 ; return catalan ( n / 2 ) ; } public static void Main ( ) { int n = 6 ; Console . Write ( " Total ▁ possible ▁ expressions " + " of ▁ length ▁ " + n + " ▁ is ▁ " + findWays ( 6 ) ) ; } }
Program to evaluate simple expressions | C # program to evaluate a given expression ; A utility function to check if a given character is operand ; utility function to find value of and operand ; This function evaluates simple expressions . It returns - 1 if the given expression is invalid . ; Base Case : Given expression is empty ; The first character must be an operand , find its value ; Traverse the remaining characters in pairs ; The next character must be an operator , and next to next an operand ; If next to next character is not an operand ; Update result according to the operator ; If not a valid operator ; Driver program to test above function
using System ; class GFG { static bool isOperand ( char c ) { return ( c >= '0' && c <= '9' ) ; } static int value ( char c ) { return ( int ) ( c - '0' ) ; } static int evaluate ( string exp ) { if ( exp . Length == 0 ) return - 1 ; int res = value ( exp [ 0 ] ) ; for ( int i = 1 ; i < exp . Length ; i += 2 ) { char opr = exp [ i ] , opd = exp [ i + 1 ] ; if ( isOperand ( opd ) == false ) return - 1 ; if ( opr == ' + ' ) res += value ( opd ) ; else if ( opr == ' - ' ) res -= value ( opd ) ; else if ( opr == ' * ' ) res *= value ( opd ) ; else if ( opr == ' / ' ) res /= value ( opd ) ; else return - 1 ; } return res ; } static void Main ( ) { string expr1 = "1 + 2*5 + 3" ; int res = evaluate ( expr1 ) ; if ( res == - 1 ) Console . WriteLine ( expr1 + " ▁ is ▁ Invalid " ) ; else Console . WriteLine ( " Value ▁ of ▁ " + expr1 + " ▁ is ▁ " + res ) ; string expr2 = "1 + 2*3" ; res = evaluate ( expr2 ) ; if ( res == - 1 ) Console . WriteLine ( expr2 + " ▁ is ▁ Invalid " ) ; else Console . WriteLine ( " Value ▁ of ▁ " + expr2 + " ▁ is ▁ " + res ) ; string expr3 = "4-2 + 6*3" ; res = evaluate ( expr3 ) ; if ( res == - 1 ) Console . WriteLine ( expr3 + " ▁ is ▁ Invalid " ) ; else Console . WriteLine ( " Value ▁ of ▁ " + expr3 + " ▁ is ▁ " + res ) ; string expr4 = "1 + + 2" ; res = evaluate ( expr4 ) ; if ( res == - 1 ) Console . WriteLine ( expr4 + " ▁ is ▁ Invalid " ) ; else Console . WriteLine ( " Value ▁ of ▁ " + expr4 + " ▁ is ▁ " + res ) ; } }
Program to print first n Fibonacci Numbers | Set 1 | C # program to print first n Fibonacci Numbers ; Method to print first n Fibonacci Numbers ; Driver Code
using System ; class Test { static void printFibonacciNumbers ( int n ) { int f1 = 0 , f2 = 1 , i ; if ( n < 1 ) return ; Console . Write ( f1 + " ▁ " ) ; for ( i = 1 ; i < n ; i ++ ) { Console . Write ( f2 + " ▁ " ) ; int next = f1 + f2 ; f1 = f2 ; f2 = next ; } } public static void Main ( ) { printFibonacciNumbers ( 7 ) ; } }
Program to find LCM of two numbers | C # program to find LCM of two numbers . ; Recursive method to return gcd of a and b ; method to return LCM of two numbers ; Driver method
using System ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int lcm ( int a , int b ) { return ( a / gcd ( a , b ) ) * b ; } public static void Main ( ) { int a = 15 , b = 20 ; Console . WriteLine ( " LCM ▁ of ▁ " + a + " ▁ and ▁ " + b + " ▁ is ▁ " + lcm ( a , b ) ) ; } }