"Find the two repeating elements in a given array | C # code to Find the two repeating elements in a given array ; Will hold xor of all elements ; Will have only single set bit of xor ; Get the xor of all elements in arr [ ] and { 1 , 2 . . n } ; Get the rightmost set bit in set_bit_no ; Now divide elements in two sets by comparing rightmost set bit of xor with bit at same position in each element . ; XOR of first set in arr [ ] ; XOR of second set in arr [ ] ; XOR of first set in arr [ ] and { 1 , 2 , ... n } ; XOR of second set in arr [ ] and { 1 , 2 , ... n } ; Driver program to test the above function"
Solution in C#:

using System ; class GFG { static void printRepeating ( int [ ] arr , int size ) { int xor = arr [ 0 ] ; int set_bit_no ; int i ; int n = size - 2 ; int x = 0 , y = 0 ; for ( i = 1 ; i < size ; i ++ ) xor ^= arr [ i ] ; for ( i = 1 ; i <= n ; i ++ ) xor ^= i ; set_bit_no = ( xor & ~ ( xor - 1 ) ) ; for ( i = 0 ; i < size ; i ++ ) { int a = arr [ i ] & set_bit_no ; if ( a != 0 ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } for ( i = 1 ; i <= n ; i ++ ) { int a = i & set_bit_no ; if ( a != 0 ) x = x ^ i ; else y = y ^ i ; } Console . WriteLine ( " The ▁ two " + " ▁ reppeated ▁ elements ▁ are ▁ : " ) ; Console . Write ( x + " ▁ " + y ) ; } public static void Main ( ) { int [ ] arr = { 4 , 2 , 4 , 5 , 2 , 3 , 1 } ; int arr_size = arr . Length ; printRepeating ( arr , arr_size ) ; } }


"Find the two repeating elements in a given array | C # program to Find the two repeating elements in a given array ; Function ; driver code"
Solution in C#:

using System ; class GFG { static void printRepeating ( int [ ] arr , int size ) { int [ ] count = new int [ size ] ; int i ; Console . Write ( " Repeated ▁ elements ▁ are : ▁ " ) ; for ( i = 0 ; i < size ; i ++ ) { if ( count [ arr [ i ] ] == 1 ) Console . Write ( arr [ i ] + " ▁ " ) ; else count [ arr [ i ] ] ++ ; } } public static void Main ( ) { int [ ] arr = { 4 , 2 , 4 , 5 , 2 , 3 , 1 } ; int arr_size = arr . Length ; printRepeating ( arr , arr_size ) ; } }


"Find the type of triangle from the given sides | C # implementation to find the type of triangle with the help of the sides ; Function to find the type of triangle with the help of sides ; Driver Code ; Function Call"
Solution in C#:

using System ; class GFG { static void checkTypeOfTriangle ( int a , int b , int c ) { int sqa = ( int ) Math . Pow ( a , 2 ) ; int sqb = ( int ) Math . Pow ( b , 2 ) ; int sqc = ( int ) Math . Pow ( c , 2 ) ; if ( sqa == sqa + sqb sqb == sqa + sqc sqc == sqa + sqb ) { Console . Write ( " Right - angled ▁ Triangle " ) ; } else if ( sqa > sqc + sqb sqb > sqa + sqc sqc > sqa + sqb ) { Console . Write ( " Obtuse - angled ▁ Triangle " ) ; } else { Console . Write ( " Acute - angled ▁ Triangle " ) ; } } public static void Main ( String [ ] args ) { int a , b , c ; a = 2 ; b = 2 ; c = 2 ; checkTypeOfTriangle ( a , b , c ) ; } }


"Find the unit place digit of sum of N factorials | C # program to find the unit place digit of the first N natural numbers factorials ; Function to find the unit 's place digit ; Let us write for cases when N is smaller than or equal to 4. ; We know following ( 1 ! + 2 ! + 3 ! + 4 ! ) % 10 = 3 else ( N >= 4 ) ; Driver code"
Solution in C#:

using System ; class GFG { static int get_unit_digit ( int N ) { if ( N == 0 N == 1 ) return 1 ; else if ( N == 2 ) return 3 ; else if ( N == 3 ) return 9 ; return 3 ; } static public void Main ( ) { int N = 1 ; for ( N = 0 ; N <= 10 ; N ++ ) Console . WriteLine ( " For ▁ N ▁ = ▁ " + N + " ▁ : ▁ " + get_unit_digit ( N ) ) ; } }


"Find the value of N XOR 'ed to itself K times | C # implementation of the approach ; Function to return n ^ n ^ ... k times ; Find the result ; Driver code"
Solution in C#:

using System ; class GFG { static int xorK ( int n , int k ) { int res = n ; for ( int i = 1 ; i < k ; i ++ ) res = ( res ^ n ) ; return n ; } static public void Main ( ) { int n = 123 , k = 3 ; Console . Write ( xorK ( n , k ) ) ; } }


"Find the value of N XOR 'ed to itself K times | C # implementation of the approach ; Function to return n ^ n ^ ... k times ; If k is odd the answer is the number itself ; Else the answer is 0 ; Driver code"
Solution in C#:

using System ; class GFG { static int xorK ( int n , int k ) { if ( k % 2 == 1 ) return n ; return 0 ; } public static void Main ( String [ ] args ) { int n = 123 , k = 3 ; Console . Write ( xorK ( n , k ) ) ; } }


"Find the value of N when F ( N ) = f ( a ) + f ( b ) where a + b is the minimum possible and a * b = N | C # implementation of the approach ; Function to return the value of F ( N ) ; Base cases ; Count the number of times a number if divisible by 2 ; Return the summation ; Driver code"
Solution in C#:

using System ; class GFG { static int getValueOfF ( int n ) { if ( n == 1 ) return 0 ; if ( n == 2 ) return 1 ; int cnt = 0 ; while ( n % 2 == 0 ) { cnt += 1 ; n /= 2 ; } return 2 * cnt ; } static public void Main ( ) { int n = 20 ; Console . WriteLine ( getValueOfF ( n ) ) ; } }


"Find the value of P and modular inverse of Q modulo 998244353 | C # implementation to find the value of P . Q - 1 mod 998244353 ; Function to find the value of P * Q ^ - 1 mod 998244353 ; Loop to find the value until the expo is not zero ; Multiply p with q if expo is odd ; Reduce the value of expo by 2 ; Driver code ; Function call"
Solution in C#:

using System ; class GFG { static long calculate ( long p , long q ) { long mod = 998244353 , expo ; expo = mod - 2 ; while ( expo != 0 ) { if ( ( expo & 1 ) == 1 ) { p = ( p * q ) % mod ; } q = ( q * q ) % mod ; expo >>= 1 ; } return p ; } public static void Main ( string [ ] args ) { long p = 1 , q = 4 ; Console . WriteLine ( calculate ( p , q ) ) ; } }


"Find the value of f ( n ) / f ( r ) * f ( n | C # program to find the value of f ( n ) / f ( r ) * f ( n - r ) ; Function to find value of given F ( n ) ; iterate over n ; calculate result ; return the result ; Driver code"
Solution in C#:

using System ; public class GFG { static int calcFunction ( int n , int r ) { int finalDenominator = 1 ; int mx = Math . Max ( r , n - r ) ; for ( int i = mx + 1 ; i <= n ; i ++ ) { int denominator = ( int ) Math . Pow ( i , i ) ; int numerator = ( int ) Math . Pow ( i - mx , i - mx ) ; finalDenominator = ( finalDenominator * denominator ) / numerator ; } return finalDenominator ; } public static void Main ( ) { int n = 6 , r = 2 ; Console . WriteLine ( "1 / " + calcFunction ( n , r ) ) ; } }


"Find the value of max ( f ( x ) ) | C # implementation of above approach ; Function to calculate the value ; forming the prefix sum arrays ; Taking the query ; finding the sum in the range l to r in array a ; finding the sum in the range l to r in array b ; Finding the max value of the function ; Finding the min value of the function ; Driver code"
Solution in C#:

using System ; class GFG { static int CONS = 32766 ; static void calc ( int [ ] a , int [ ] b , int [ ] lr , int q , int n ) { int M , m , i , l , r , suma , sumb , cc ; cc = 0 ; for ( i = 0 ; i < n - 1 ; ++ i ) { a [ i + 1 ] += a [ i ] ; b [ i + 1 ] += b [ i ] ; } while ( q != 0 ) { l = lr [ cc ++ ] ; r = lr [ cc ++ ] ; l -= 2 ; r -= 1 ; suma = a [ r ] ; sumb = b [ r ] ; if ( l >= 0 ) { suma -= a [ l ] ; sumb -= b [ l ] ; } M = Math . Max ( CONS * suma + CONS * sumb , - CONS * suma - CONS * sumb ) ; M = Math . Max ( M , Math . Max ( CONS * suma - CONS * sumb , - CONS * suma + CONS * sumb ) ) ; m = Math . Min ( CONS * suma + CONS * sumb , - CONS * suma - CONS * sumb ) ; m = Math . Min ( m , Math . Min ( CONS * suma - CONS * sumb , - CONS * suma + CONS * sumb ) ) ; Console . WriteLine ( ( M - m ) ) ; q -- ; } } public static void Main ( ) { int n = 5 , q = 2 ; int [ ] a = { 0 , 7 , 3 , 4 , 5 } ; int [ ] b = { 0 , 3 , 1 , 2 , 3 } ; int [ ] lr = new int [ q * 2 ] ; lr [ 0 ] = 1 ; lr [ 1 ] = 1 ; lr [ 2 ] = 1 ; lr [ 3 ] = 3 ; calc ( a , b , lr , q , n ) ; } }


"Find the value of the function Y = ( X ^ 6 + X ^ 2 + 9894845 ) % 971 | C # implementation of above approach ; computing ( a ^ b ) % c ; Driver code"
Solution in C#:

using System ; class GFG { static long modpow ( long base1 , long exp , long modulus ) { base1 %= modulus ; long result = 1 ; while ( exp > 0 ) { if ( ( exp & 1 ) > 0 ) result = ( result * base1 ) % modulus ; base1 = ( base1 * base1 ) % modulus ; exp >>= 1 ; } return result ; } public static void Main ( ) { long n = 654654 ; long mod = 971 ; Console . WriteLine ( ( ( modpow ( n , 6 , mod ) + modpow ( n , 2 , mod ) ) % mod + 355 ) % mod ) ; } }


"Find the values of X and Y in the Given Equations | C # program to find the values of X and Y using the given equations ; Function to find the values of X and Y ; base condition ; required answer ; Driver Code"
Solution in C#:

using System ; class GFG { static void findValues ( int a , int b ) { if ( ( a - b ) % 2 == 1 ) { Console . Write ( " - 1" ) ; return ; } Console . WriteLine ( ( ( a - b ) / 2 ) + " ▁ " + ( ( a + b ) / 2 ) ) ; } static public void Main ( ) { int a = 12 , b = 8 ; findValues ( a , b ) ; } }


"Find the vertex diagonally opposite to the vertex M from an N | C # program for the above approach ; Function to return the required vertex ; Case 1 : ; Case 2 : ; Driver Code"
Solution in C#:

using System ; class GFG { static int getPosition ( int N , int M ) { if ( M > ( N / 2 ) ) { return ( M - ( N / 2 ) ) ; } return ( M + ( N / 2 ) ) ; } public static void Main ( String [ ] args ) { int N = 8 , M = 5 ; Console . Write ( getPosition ( N , M ) ) ; } }


"Find the volume of rectangular right wedge | C # implementation of the approach ; Function to return the volume of the rectangular right wedge ; Driver code"
Solution in C#:

using System ; class GFG { static double volumeRec ( double a , double b , double e , double h ) { return ( ( ( b * h ) / 6 ) * ( 2 * a + e ) ) ; } public static void Main ( ) { double a = 2 , b = 5 , e = 5 , h = 6 ; Console . WriteLine ( " Volume ▁ = ▁ " + volumeRec ( a , b , e , h ) ) ; } }


"Find the winner by adding Pairwise difference of elements in the array until Possible | C # implementation of the approach ; Function to calculate gcd ; Function to return the winner of the game ; To store the gcd of the original array ; To store the maximum element from the original array ; If number of moves are odd ; Driver Code"
Solution in C#:

using System ; class GFG { static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } static char getWinner ( int [ ] arr , int n ) { int gcd = arr [ 0 ] ; int maxEle = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { gcd = __gcd ( gcd , arr [ i ] ) ; maxEle = Math . Max ( maxEle , arr [ i ] ) ; } int totalMoves = ( maxEle / gcd ) - n ; if ( totalMoves % 2 == 1 ) return ' A ' ; return ' B ' ; } public static void Main ( ) { int [ ] arr = { 5 , 6 , 7 } ; int n = arr . Length ; Console . Write ( getWinner ( arr , n ) ) ; } }


"Find the winner in nim | C # to find nim - game winner ; function to find winner of NIM - game ; case when Alice is winner ; when Bob is winner ; Driver code"
Solution in C#:

using System ; class GFG { static String findWinner ( int [ ] A , int n ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) res ^= A [ i ] ; if ( res == 0 n % 2 == 0 ) return " Alice " ; else return " Bob " ; } public static void Main ( ) { int [ ] A = { 1 , 4 , 3 , 5 } ; int n = A . Length ; Console . WriteLine ( " Winner ▁ = ▁ " + findWinner ( A , n ) ) ; } }


"Find the winner of a game of donating i candies in every i | C # program for the above approach ; Function to find the winning player in a game of donating i candies to opponent in i - th move ; Steps in which number of candies of player A finishes ; Steps in which number of candies of player B finishes ; If A 's candies finishes first ; Otherwise ; Driver code ; Candies possessed by player A ; Candies possessed by player B"
Solution in C#:

using System ; class GFG { static void stepscount ( int a , int b ) { int chanceA = 2 * a - 1 ; int chanceB = 2 * b ; if ( chanceA < chanceB ) { Console . Write ( " B " ) ; } else if ( chanceB < chanceA ) { Console . Write ( " A " ) ; } } static void Main ( ) { int A = 2 ; int B = 3 ; stepscount ( A , B ) ; } }


"Find the winner of a game of removing any number of stones from the least indexed non | C # program for the above approach ; Function to find the winner of game between A and B ; win = 1 means B is winner win = 0 means A is winner ; If size is even , winner is B ; If size is odd , winner is A ; Stone will be removed by B ; B will take n - 1 stones from current pile having n stones and force A to pick 1 stone ; Stone will be removed by A ; A will take n - 1 stones from current pile having n stones and force B to pick 1 stone ; Print the winner accordingly ; Driver Code ; Given piles of stone ; Function call"
Solution in C#:

using System ; class GFG { static void findWinner ( int [ ] a , int n ) { int win = 0 ; if ( n % 2 == 0 ) win = 1 ; else win = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( i % 2 == 1 ) { if ( win == 0 && a [ i ] > 1 ) win = 1 ; } else { if ( win == 1 && a [ i ] > 1 ) win = 0 ; } } if ( win == 0 ) Console . Write ( " A " ) ; else Console . Write ( " B " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 1 , 2 } ; int N = arr . Length ; findWinner ( arr , N ) ; } }


"Find the winner of a game of removing at most 3 stones from a pile in each turn | C # program for the above approach ; Function to find the maximum score of Player 1 ; Base Case ; If the result is already computed , then return the result ; Variable to store maximum score ; Pick one stone ; Pick 2 stones ; Pick 3 stones ; Return the score of the player ; Function to find the winner of the game ; Create a 1D table , dp of size N ; Store the result ; Player 1 wins ; PLayer 2 wins ; Tie ; Driver Code ; Given Input ; Function Call"
Solution in C#:

using System ; public class GFG { static int ans = 0 ; static int maximumStonesUtil ( int [ ] arr , int n , int i , int [ ] dp ) { if ( i >= n ) return 0 ; ans = dp [ i ] ; if ( ans != - 1 ) return ans ; ans = int . MinValue ; ans = Math . Max ( ans , arr [ i ] - maximumStonesUtil ( arr , n , i + 1 , dp ) ) ; if ( i + 1 < n ) ans = Math . Max ( ans , arr [ i ] + arr [ i + 1 ] - maximumStonesUtil ( arr , n , i + 2 , dp ) ) ; if ( i + 2 < n ) ans = Math . Max ( ans , arr [ i ] + arr [ i + 1 ] + arr [ i + 2 ] - maximumStonesUtil ( arr , n , i + 3 , dp ) ) ; return ans ; } static String maximumStones ( int [ ] arr , int n ) { int [ ] dp = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) dp [ i ] = - 1 ; int res = maximumStonesUtil ( arr , n , 0 , dp ) ; if ( res > 0 ) return " Player1" ; else if ( res < 0 ) return " Player2" ; else return " Tie " ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 7 } ; int n = arr . Length ; Console . Write ( maximumStones ( arr , n ) ) ; } }


"Find the winner of a game where scores are given as a binary string | C # program for predicting winner ; function for winner prediction ; increase count ; check losing condition ; check winning condition ; check tie on n - 1 point ; increase count ; check for 2 point lead ; condition of lost ; condition of win ; Driver Code"
Solution in C#:

using System ; class GFG { public static void predictWinner ( string score , int n ) { int [ ] count = new int [ 2 ] ; int i ; for ( i = 0 ; i < score . Length ; i ++ ) { count [ score [ i ] - '0' ] ++ ; if ( count [ 0 ] == n && count [ 1 ] < n - 1 ) { Console . Write ( " GEEKS ▁ lost " ) ; return ; } if ( count [ 1 ] == n && count [ 0 ] < n - 1 ) { Console . Write ( " GEEKS ▁ won " ) ; return ; } if ( count [ 0 ] == n - 1 && count [ 1 ] == n - 1 ) { count [ 0 ] = 0 ; count [ 1 ] = 0 ; break ; } } for ( i ++ ; i < score . Length ; i ++ ) { count [ score [ i ] - '0' ] ++ ; if ( Math . Abs ( count [ 0 ] - count [ 1 ] ) == 2 ) { if ( count [ 0 ] > count [ 1 ] ) { Console . Write ( " GEEKS ▁ lost " ) ; } else { Console . Write ( " GEEKS ▁ won " ) ; } return ; } } } public static void Main ( string [ ] args ) { string score = "1001010101111011101111" ; int n = 15 ; predictWinner ( score , n ) ; } }


"Find the winner of game of removing array elements having GCD equal to 1 | C # program to implement the above approach ; Function to find the winner of the game by removing array elements whose GCD is 1 ; mp [ i ] : Stores count of array elements whose prime factor is i ; Traverse the array ; Calculate the prime factors of arr [ i ] ; If arr [ i ] is divisible by j ; Update mp [ j ] ; Update arr [ i ] ; If arr [ i ] exceeds 1 ; Stores maximum value present in the Map ; Traverse the map ; Update maxCnt ; If n is an even number ; If maxCnt is greater than or equal to n - 1 ; Player 1 wins ; Player 2 wins ; If maxCnt equal to n ; Player 1 wins ; Player 2 wins ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static void findWinnerGameRemoveGCD ( int [ ] arr , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 2 ; j * j <= arr [ i ] ; j ++ ) { if ( arr [ i ] % j == 0 ) { if ( mp . ContainsKey ( j ) ) { mp [ j ] = mp [ j ] + 1 ; } else { mp . Add ( j , 1 ) ; } while ( arr [ i ] % j == 0 ) { arr [ i ] = arr [ i ] / j ; } } } if ( arr [ i ] > 1 ) { if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1 ; } else { mp . Add ( arr [ i ] , 1 ) ; } } } int maxCnt = 0 ; foreach ( KeyValuePair < int , int > i in mp ) { maxCnt = Math . Max ( maxCnt , i . Value ) ; } if ( n % 2 == 0 ) { if ( maxCnt >= n - 1 ) { Console . Write ( " Player ▁ 1" ) ; } else { Console . Write ( " Player ▁ 2" ) ; } } else { if ( maxCnt == n ) { Console . Write ( " Player ▁ 1" ) ; } else { Console . Write ( " Player ▁ 2" ) ; } } } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 4 , 8 } ; int N = arr . Length ; findWinnerGameRemoveGCD ( arr , N ) ; } }


"Find the winner of game of repeatedly removing the first character to empty given string | C # program to implement the above approach ; Function to find the winner of a game of repeatedly removing the first character to empty a String ; Store characters of each String of the array [ ] arr ; Stores count of Strings in [ ] arr ; Traverse the array [ ] arr ; Stores length of current String ; Traverse the String ; Insert arr [ i , j ] ; 1 st Player starts the game ; Stores the player number for the next turn ; Remove 1 st character of current String ; Update player number for the next turn ; Driver Code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static void find_Winner ( String [ ] arr , int N ) { List < char > [ ] Q = new List < char > [ N ] ; for ( int i = 0 ; i < Q . Length ; i ++ ) Q [ i ] = new List < char > ( ) ; int M = arr . Length ; for ( int i = 0 ; i < M ; i ++ ) { int len = arr [ i ] . Length ; for ( int j = 0 ; j < len ; j ++ ) { Q [ i ] . Add ( arr [ i ] [ j ] ) ; } } int player = 0 ; while ( Q [ player ] . Count > 0 ) { int nextPlayer = Q [ player ] [ 0 ] - '0' - 1 ; Q [ player ] . RemoveAt ( 0 ) ; player = nextPlayer ; } Console . Write ( " Player ▁ " + ( player + 1 ) ) ; } public static void Main ( String [ ] args ) { int N = 3 ; String [ ] arr = { "323" , "2" , "2" } ; find_Winner ( arr , N ) ; } }


"Find the winner of the Game of removing odd or replacing even array elements | C # program for the above approach ; Function to evaluate the winner of the game ; Stores count of odd array elements ; Stores count of even array elements ; Traverse the array ; If array element is odd ; Otherwise ; If count of even is zero ; If count of odd is even ; If count of odd is odd ; If count of odd is odd and count of even is one ; Otherwise ; Driver Code"
Solution in C#:

using System ; class GFG { static void findWinner ( int [ ] arr , int N ) { int odd = 0 ; int even = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { odd ++ ; } else { even ++ ; } } if ( even == 0 ) { if ( odd % 2 == 0 ) { Console . WriteLine ( " Player ▁ 2" ) ; } else if ( odd % 2 == 1 ) { Console . WriteLine ( " Player ▁ 1" ) ; } } else if ( even == 1 && odd % 2 == 1 ) { Console . WriteLine ( " Player ▁ 1" ) ; } else { Console . WriteLine ( - 1 ) ; } } public static void Main ( ) { int [ ] arr = { 3 , 1 , 9 , 7 } ; int N = arr . Length ; findWinner ( arr , N ) ; } }


"Find the winner of the game based on greater number of divisors | C # implementation of the approach ; Function to return the count of divisors of elem ; Function to return the winner of the game ; Convert every element of A [ ] to their divisor count ; Convert every element of B [ ] to their divisor count ; Sort both the arrays ; For every element of A apply Binary Search to find number of pairs where A wins ; B wins if A doesnot win ; Driver code"
Solution in C#:

using System ; class GFG { static int divisorcount ( int elem ) { int ans = 0 ; for ( int i = 1 ; i <= Math . Sqrt ( elem ) ; i ++ ) { if ( elem % i == 0 ) { if ( i * i == elem ) ans ++ ; else ans += 2 ; } } return ans ; } static string findwinner ( int [ ] A , int [ ] B , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = divisorcount ( A [ i ] ) ; } for ( int i = 0 ; i < M ; i ++ ) { B [ i ] = divisorcount ( B [ i ] ) ; } Array . Sort ( A ) ; Array . Sort ( B ) ; int winA = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int val = A [ i ] ; int start = 0 ; int end = M - 1 ; int index = - 1 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( B [ mid ] <= val ) { index = mid ; start = mid + 1 ; } else { end = mid - 1 ; } } winA += ( index + 1 ) ; } int winB = N * M - winA ; if ( winA > winB ) { return " A " ; } else if ( winB > winA ) { return " B " ; } return " Draw " ; } public static void Main ( ) { int [ ] A = { 4 , 12 , 24 } ; int N = A . Length ; int [ ] B = { 25 , 28 , 13 , 45 } ; int M = B . Length ; Console . Write ( findwinner ( A , B , N , M ) ) ; } }


"Find the winner of the game | C # implementation of the approach ; Function to find the winner of the game ; To store the strings for both the players ; If the index is even ; Append the current character to player A 's string ; If the index is odd ; Append the current character to player B 's string ; Sort both the strings to get the lexicographically smallest string possible ; Copmpare both the strings to find the winner of the game ; Driver code"
Solution in C#:

using System ; class GFG { static void find_winner ( String str , int n ) { String str1 = " " , str2 = " " ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { str1 += str [ i ] ; } else { str2 += str [ i ] ; } } char [ ] a = str1 . ToCharArray ( ) ; Array . Sort ( a ) ; char [ ] b = str2 . ToCharArray ( ) ; Array . Sort ( b ) ; str1 = new String ( a ) ; str2 = new String ( b ) ; if ( str1 . CompareTo ( str2 ) < 0 ) Console . Write ( " A " ) ; else if ( str1 . CompareTo ( str2 ) > 0 ) Console . Write ( " B " ) ; else Console . Write ( " Tie " ) ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; int n = str . Length ; find_winner ( str , n ) ; } }


"Find the word from a given sentence having given word as prefix | C # program for the above approach ; Function to find the position of the string having word as prefix ; Initialize an List ; Extract words from the sentence ; Traverse each word ; Traverse the characters of word ; If prefix does not match ; Otherwise ; Return the word ; Return - 1 if not present ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static String isPrefixOfWord ( String sentence , String Word ) { String [ ] a = sentence . Split ( ' ▁ ' ) ; List < String > v = new List < String > ( ) ; foreach ( String e in a ) v . Add ( e ) ; for ( int i = 0 ; i < v . Count ; i ++ ) { for ( int j = 0 ; j < v [ i ] . Length ; j ++ ) { if ( v [ i ] [ j ] != Word [ j ] ) break ; else if ( j == Word . Length - 1 ) return v [ i ] ; } } return " - 1" ; } public static void Main ( String [ ] args ) { String s = " Welcome ▁ to ▁ Geeksforgeeks " ; String word = " Gee " ; Console . WriteLine ( isPrefixOfWord ( s , word ) ) ; } }


"Find the word with most anagrams in a given sentence | C # program to find the word with most anagrams in a sentence ; Function to find the word with maximum number of anagrams ; Primes assigned to 26 alphabets ; Stores the product and word mappings ; Stores the frequencies of products ; Calculate the product of primes assigned ; If product already exists ; Otherwise ; Fetch the most frequent product ; Return a string with that product ; Driver Code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { private static String largestAnagramGrp ( String [ ] arr ) { int [ ] prime = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37 , 41 , 43 , 47 , 53 , 59 , 61 , 67 , 71 , 73 , 79 , 83 , 89 , 97 , 101 } ; int max = - 1 ; long maxpdt = - 1 ; Dictionary < long , String > W = new Dictionary < long , String > ( ) ; Dictionary < long , int > P = new Dictionary < long , int > ( ) ; foreach ( String temp in arr ) { char [ ] c = temp . ToCharArray ( ) ; long pdt = 1 ; foreach ( char t in c ) { pdt *= prime [ t - ' a ' ] ; } if ( P . ContainsKey ( pdt ) ) { P [ pdt ] = P [ pdt ] + 1 ; } else { W . Add ( pdt , temp ) ; P . Add ( pdt , 1 ) ; } } foreach ( KeyValuePair < long , int > e in P ) { if ( max < e . Value ) { max = e . Value ; maxpdt = e . Key ; } } return W [ maxpdt ] ; } public static void Main ( String [ ] args ) { String S = " please ▁ be ▁ silent ▁ and ▁ listen " + " ▁ to ▁ what ▁ the ▁ professor ▁ says ▁ " ; String [ ] arr = S . Split ( ' ▁ ' ) ; Console . WriteLine ( largestAnagramGrp ( arr ) ) ; } }


"Find third number such that sum of all three number becomes prime | C # implementation of the above approach ; Function that will check whether number is prime or not ; Function to print the 3 rd number ; If the sum is odd ; If sum is not prime ; Driver code"
Solution in C#:

using System ; class GFG { static bool prime ( int n ) { for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static void thirdNumber ( int a , int b ) { int sum = 0 , temp = 0 ; sum = a + b ; temp = 1 ; if ( sum == 0 ) { temp = 2 ; } while ( ! prime ( sum + temp ) ) { temp += 2 ; } Console . Write ( temp ) ; } static public void Main ( ) { int a = 3 , b = 5 ; thirdNumber ( a , b ) ; } }


"Find three element from different three arrays such that a + b + c = sum | C # program to find three element from different three arrays such that a + b + c is equal to given sum ; Function to check if there is an element from each array such that sum of the three elements is equal to given sum . ; Driver Code"
Solution in C#:

using System ; public class GFG { static bool findTriplet ( int [ ] a1 , int [ ] a2 , int [ ] a3 , int n1 , int n2 , int n3 , int sum ) { for ( int i = 0 ; i < n1 ; i ++ ) for ( int j = 0 ; j < n2 ; j ++ ) for ( int k = 0 ; k < n3 ; k ++ ) if ( a1 [ i ] + a2 [ j ] + a3 [ k ] == sum ) return true ; return false ; } static public void Main ( ) { int [ ] a1 = { 1 , 2 , 3 , 4 , 5 } ; int [ ] a2 = { 2 , 3 , 6 , 1 , 2 } ; int [ ] a3 = { 3 , 2 , 4 , 5 , 6 } ; int sum = 9 ; int n1 = a1 . Length ; int n2 = a2 . Length ; int n3 = a3 . Length ; if ( findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }


"Find three element from different three arrays such that a + b + c = sum | C # program to find three element from different three arrays such that a + b + c is equal to given sum ; Function to check if there is an element from each array such that sum of the three elements is equal to given sum . ; Store elements of first array in hash ; sum last two arrays element one by one ; Consider current pair and find if there is an element in a1 [ ] such that these three form a required triplet ; Driver Code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static bool findTriplet ( int [ ] a1 , int [ ] a2 , int [ ] a3 , int n1 , int n2 , int n3 , int sum ) { HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < n1 ; i ++ ) { s . Add ( a1 [ i ] ) ; } List < int > al = new List < int > ( s ) ; for ( int i = 0 ; i < n2 ; i ++ ) { for ( int j = 0 ; j < n3 ; j ++ ) { if ( al . Contains ( sum - a2 [ i ] - a3 [ j ] ) & al . IndexOf ( sum - a2 [ i ] - a3 [ j ] ) != al [ al . Count - 1 ] ) { return true ; } } } return false ; } public static void Main ( String [ ] args ) { int [ ] a1 = { 1 , 2 , 3 , 4 , 5 } ; int [ ] a2 = { 2 , 3 , 6 , 1 , 2 } ; int [ ] a3 = { 3 , 2 , 4 , 5 , 6 } ; int sum = 9 ; int n1 = a1 . Length ; int n2 = a2 . Length ; int n3 = a3 . Length ; if ( findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }


"Find three prime numbers with given sum | C # implementation of the approach ; The vector primes holds the prime numbers ; Function to generate prime numbers ; Initialize the array elements to 0 s ; Set the non - primes to true ; Fill the vector primes with prime numbers which are marked as false in the numbers array ; Function to print three prime numbers which sum up to the number N ; Take the first prime number ; Take the second prime number ; Subtract the two prime numbers from the N to obtain the third number ; If the third number is prime ; Print the three prime numbers if the solution exists ; Driver code ; Function for generating prime numbers using Sieve of Eratosthenes ; Function to print the three prime numbers whose sum is equal to N"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static int MAX = 100001 ; static List < int > primes = new List < int > ( ) ; static void initialize ( ) { bool [ ] numbers = new bool [ MAX + 1 ] ; int n = MAX ; for ( int i = 2 ; i * i <= n ; i ++ ) if ( ! numbers [ i ] ) for ( int j = i * i ; j <= n ; j += i ) numbers [ j ] = true ; for ( int i = 2 ; i <= n ; i ++ ) if ( numbers [ i ] == false ) primes . Add ( i ) ; } static void findNums ( int num ) { bool ans = false ; int first = - 1 , second = - 1 , third = - 1 ; for ( int i = 0 ; i < num ; i ++ ) { first = primes [ i ] ; for ( int j = 0 ; j < num ; j ++ ) { second = primes [ j ] ; third = num - first - second ; if ( Array . BinarySearch ( primes . ToArray ( ) , third ) >= 0 ) { ans = true ; break ; } } if ( ans ) break ; } if ( ans ) Console . WriteLine ( first + " ▁ " + second + " ▁ " + third ) ; else Console . WriteLine ( - 1 ) ; } static void Main ( ) { int n = 101 ; initialize ( ) ; findNums ( n ) ; } }


"Find three vertices in an N | C # program for the above approach ; Function to find three vertices that subtends an angle closest to A ; Stores the closest angle to A ; Stores the count of edge which subtend an angle of A ; Iterate in the range [ 1 , N - 2 ] ; Stores the angle subtended ; If absolute ( angle - A ) is less than absolute ( mi - A ) ; Update angle to mi , and also update i to ans ; Print the vertices ; Driver Code"
Solution in C#:

using System ; class GFG { static void closestsAngle ( int N , int A ) { double mi = Int32 . MaxValue ; int ans = 0 ; for ( int i = 1 ; i < N - 1 ; i ++ ) { double angle = 180.0 * i / N ; if ( Math . Abs ( angle - A ) < Math . Abs ( mi - A ) ) { mi = angle ; ans = i ; } } Console . Write ( 2 + " ▁ " + 1 + " ▁ " + ( 2 + ans ) ) ; } public static void Main ( ) { int N = 3 , A = 15 ; closestsAngle ( N , A ) ; } }


"Find time taken for signal to reach all positions in a string | C # program to Find time taken for signal to reach all positions in a string ; Returns time needed for signal to traverse through complete string . ; for the calculation of last index ; for strings like oxoooo , xoxxoooo . . ; if coun is greater than max_length ; if ' x ' is present at the right side of max_length ; if ' x ' is present at left side of max_length ; We use ceiling function to handle odd number ' o ' s ; Driver code"
Solution in C#:

using System ; class GFG { static int maxLength ( string s , int n ) { int right = 0 , left = 0 ; int coun = 0 , max_length = int . MinValue ; s = s + '1' ; for ( int i = 0 ; i <= n ; i ++ ) { if ( s [ i ] == ' o ' ) coun ++ ; else { if ( coun > max_length ) { right = 0 ; left = 0 ; if ( s [ i ] == ' x ' ) right = 1 ; if ( ( ( i - coun ) > 0 ) && ( s [ i - coun - 1 ] == ' x ' ) ) left = 1 ; coun = ( int ) Math . Ceiling ( ( double ) coun / ( right + left ) ) ; max_length = Math . Max ( max_length , coun ) ; } coun = 0 ; } } return max_length ; } public static void Main ( ) { string s = " oooxoooooooooxooo " ; int n = s . Length ; Console . Write ( maxLength ( s , n ) ) ; } }


"Find total no of collisions taking place between the balls in which initial direction of each ball is given | C # implementation to Find total no of collisions taking place between the balls in which initial direction of each ball is given ; Function to count no of collision ; length of the string ; Driver code"
Solution in C#:

using System ; class GFG { static int count ( String s ) { int N , i , cnt = 0 , ans = 0 ; N = s . Length ; for ( i = 0 ; i < N ; i ++ ) { if ( s [ i ] == ' R ' ) cnt ++ ; if ( s [ i ] == ' L ' ) ans += cnt ; } return ans ; } public static void Main ( String [ ] args ) { String s = " RRLL " ; Console . Write ( count ( s ) ) ; } }


"Find triplets in an array whose AND is maximum | C # program to find triplet with maximum bitwise AND . ; Flag Array initially set to true for all numbers ; 2D array for bit representation of all the numbers . Initially all bits are set to 0. ; Finding bit representation of every number and storing it in bits array . ; Checking last bit of the number ; Dividing number by 2. ; maximum And number initially 0. ; Traversing the 2d binary representation . 0 th index represents 32 th bits while 32 th index represents 0 th bit . ; If cnt greater than 3 then ( 32 - i ) th bits of the number will be set . ; Setting flags of the numbers whose ith bit is not set . ; Counting the numbers whose flag are true . ; Driver code"
Solution in C#:

using System ; class GFG { static void maxTriplet ( int [ ] a , int n ) { Boolean [ ] f = new Boolean [ n ] ; for ( int i = 0 ; i < n ; ++ i ) f [ i ] = true ; int [ , ] bits = new int [ n , 33 ] ; for ( int i = 0 ; i < n ; ++ i ) { int num = a [ i ] ; int j = 32 ; while ( num > 0 ) { if ( num % 2 == 1 ) { bits [ i , j ] = 1 ; } j -- ; num >>= 1 ; } } long ans = 0 ; int cnt ; for ( int i = 0 ; i <= 32 ; ++ i ) { cnt = 0 ; for ( int j = 0 ; j < n ; ++ j ) { if ( bits [ j , i ] == 1 & f [ j ] ) { cnt ++ ; } } if ( cnt >= 3 ) { ans += ( long ) Math . Pow ( 2 , 32 - i ) ; for ( int j = 0 ; j < n ; ++ j ) { if ( bits [ j , i ] != 1 ) { f [ j ] = false ; } } } } cnt = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( f [ i ] ) { cnt ++ ; } } long NumberOfTriplets = ( cnt * ( cnt - 1 ) * ( cnt - 2 ) ) / 6 ; Console . Write ( NumberOfTriplets + " ▁ " + ans ) ; } public static void Main ( String [ ] args ) { int [ ] a = { 4 , 11 , 10 , 15 , 26 } ; int n = a . Length ; maxTriplet ( a , n ) ; } }


"Find two Fibonacci numbers whose sum can be represented as N | C # program to find two Fibonacci numbers whose sum can be represented as N ; Function to create hash table to check Fibonacci numbers ; Storing the first two numbers in the hash ; Finding Fibonacci numbers up to N and storing them in the hash ; Function to find the Fibonacci pair with the given sum ; creating a set containing all fibonacci numbers ; Traversing all numbers to find first pair ; If both i and ( N - i ) are Fibonacci ; Printing the pair because i + ( N - i ) = N ; If no fibonacci pair is found whose sum is equal to n ; Driven code"
Solution in C#:

 using System ; using System . Collections . Generic ; class GFG { static void createHash ( HashSet < int > hash , int maxElement ) { int prev = 0 , curr = 1 ; hash . Add ( prev ) ; hash . Add ( curr ) ; while ( curr < maxElement ) { int temp = curr + prev ; hash . Add ( temp ) ; prev = curr ; curr = temp ; } } static void findFibonacciPair ( int n ) { HashSet < int > hash = new HashSet < int > ( ) ; createHash ( hash , n ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( hash . Contains ( i ) && hash . Contains ( n - i ) ) { Console . Write ( i + " , ▁ " + ( n - i ) + "
 " ) ; return ; } } Console . Write ( " - 1
 " ) ; } public static void Main ( String [ ] args ) { int N = 90 ; findFibonacciPair ( N ) ; } }


"Find two co | C # implementation of the approach ;  ; Function to find the required numbers ; GCD of the given numbers ; Printing the required numbers ; Driver code"
Solution in C#:

using System ; class GFG { public static int findGCD ( int a , int b ) { if ( b == 0 ) return a ; else return findGCD ( b , a % b ) ; } static void findNumbers ( int a , int b ) { int gcd = findGCD ( a , b ) ; Console . Write ( ( a / gcd ) + " ▁ " + ( b / gcd ) ) ; } static public void Main ( ) { int a = 12 , b = 16 ; findNumbers ( a , b ) ; } }


"Find two distinct numbers such that their LCM lies in given range | C # program for the above approach ; Function to find two distinct numbers X and Y s . t . their LCM lies between L and R and X , Y are minimum possible ; Check if 2 * L lies in range L , R ; Print the answer ; Driver Code ; Given value of ranges ; Function call"
Solution in C#:

using System ; class GFG { static void answer ( int L , int R ) { if ( 2 * L <= R ) Console . WriteLine ( L + " , ▁ " + ( 2 * L ) ) ; else Console . WriteLine ( " - 1" ) ; } public static void Main ( ) { int L = 3 , R = 8 ; answer ( L , R ) ; } }


"Find two distinct prime numbers with given product | C # program to find a distinct prime number pair whose product is equal to given number ; Function to generate all prime numbers less than n ; Initialize all entries of bool array as true . A value in isPrime [ i ] will finally be false if i is Not a prime , else true bool isPrime [ n + 1 ] ; ; If isPrime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Function to print a prime pair with given product ; Generating primes using Sieve ; Traversing all numbers to find first pair ; Driven Code"
Solution in C#:

using System ; class GFG { static void SieveOfEratosthenes ( int n , bool [ ] isPrime ) { isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( int i = 2 ; i <= n ; i ++ ) isPrime [ i ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( isPrime [ p ] == true ) { for ( int i = p * 2 ; i <= n ; i += p ) isPrime [ i ] = false ; } } } static void findPrimePair ( int n ) { int flag = 0 ; bool [ ] isPrime = new bool [ n + 1 ] ; SieveOfEratosthenes ( n , isPrime ) ; for ( int i = 2 ; i < n ; i ++ ) { int x = n / i ; if ( isPrime [ i ] && isPrime [ x ] && x != i && x * i == n ) { Console . Write ( i + " ▁ " + x ) ; flag = 1 ; return ; } } if ( flag == 0 ) Console . Write ( " No ▁ such ▁ pair ▁ found " ) ; } public static void Main ( ) { int n = 39 ; findPrimePair ( n ) ; } }


"Find two equal subsequences of maximum length with at least one different index | C # implementation of the approach ; Function to return the required length of the subsequences ; To store the result ; To store the last visited position of lowercase letters ; Initialisation of frequency array to - 1 to indicate no character has previously occured ; For every character of the String ; Get the index of the current character ; If the current character has appeared before in the String ; Update the result ; Update the last position of the current character ; Driver code"
Solution in C#:

using System ; class GFG { static int MAX = 26 ; static int maxLength ( string str , int len ) { int res = 0 ; int [ ] lastPos = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { lastPos [ i ] = - 1 ; } for ( int i = 0 ; i < len ; i ++ ) { int C = str [ i ] - ' a ' ; if ( lastPos [ C ] != - 1 ) { res = Math . Max ( len - ( i - lastPos [ C ] - 1 ) - 1 , res ) ; } lastPos [ C ] = i ; } return res ; } public static void Main ( ) { string str = " geeksforgeeks " ; int len = str . Length ; Console . WriteLine ( maxLength ( str , len ) ) ; } }


"Find two non | C # program for the above approach ; Function to check if two non - intersecting subarrays with equal sum exists or not ; Sort the given array ; Traverse the array ; Check for duplicate elements ; If no duplicate element is present in the array ; Driver code ; Given array ; Size of array"
Solution in C#:

using System ; class GFG { static void findSubarrays ( int [ ] arr , int N ) { Array . Sort ( arr ) ; int i = 0 ; for ( i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { Console . WriteLine ( " YES " ) ; return ; } } Console . WriteLine ( " NO " ) ; } public static void Main ( ) { int [ ] arr = { 4 , 3 , 0 , 1 , 2 , 0 } ; int N = arr . Length ; findSubarrays ( arr , N ) ; } }


"Find two non | C # program to find two non - overlapping pairs having equal sum in an Array ; Declare a pair ; Function to find two non - overlapping pairs with same sum in an array ; First create an empty map key -> which is sum of a pair of elements in the array value -> list storing index of every pair having that sum ; Consider every pair ( A [ i ] , A [ j ] ) where ( j > i ) ; Calculate sum of current pair ; If sum is already present in the map ; Check every pair having desired sum ; If pairs don 't overlap, print  them and return ; Insert current pair into the map ; Driver Code"
Solution in C#:

using System ; using System . Collections . Generic ; class Pair { public int x , y ; public Pair ( int x , int y ) { this . x = x ; this . y = y ; } } class GFG { public static void findPairs ( int [ ] A ) { Dictionary < int , List < Pair > > map = new Dictionary < int , List < Pair > > ( ) ; for ( int i = 0 ; i < A . Length - 1 ; i ++ ) { for ( int j = i + 1 ; j < A . Length ; j ++ ) { int sum = A [ i ] + A [ j ] ; if ( map . ContainsKey ( sum ) ) { foreach ( Pair pair in map [ sum ] ) { int x = pair . x ; int y = pair . y ; if ( ( x != i && x != j ) && ( y != i && y != j ) ) { Console . WriteLine ( " Pair ▁ First ( " + A [ i ] + " , ▁ " + A [ j ] + " ) " ) ; Console . WriteLine ( " Pair ▁ Second ▁ ( " + A [ x ] + " , ▁ " + A [ y ] + " ) " ) ; return ; } } } map [ sum ] = new List < Pair > ( ) ; map [ sum ] . Add ( new Pair ( i , j ) ) ; } } Console . Write ( " No ▁ such ▁ non - overlapping ▁ pairs ▁ present " ) ; } public static void Main ( String [ ] args ) { int [ ] A = { 8 , 4 , 7 , 8 , 4 } ; findPairs ( A ) ; } }


"Find two numbers from their sum and OR | C # code for the above approach ; Function to find the two integers from the given sum and Bitwise OR value ; Check if Z is non negative ; Iterate through all the bits ; Find the kth bit of A & B ; Find the kth bit of A | B ; If bit1 = 1 and bit2 = 0 , then there will be no possible pairs ; Print the possible pairs ; Driver Code"
Solution in C#:

using System ; public class GFG { static int MaxBit = 32 ; static void possiblePair ( int X , int Y ) { int Z = Y - X ; if ( Z < 0 ) { Console . Write ( " - 1" ) ; } for ( int k = 0 ; k < MaxBit ; k ++ ) { int bit1 = ( Z >> k ) & 1 ; int bit2 = ( Z >> k ) & 1 ; if ( bit1 != 0 && bit2 == 0 ) { Console . Write ( " - 1" ) ; } } Console . Write ( Z + " ▁ " + X ) ; } static public void Main ( ) { int X = 7 , Y = 11 ; possiblePair ( X , Y ) ; } }


"Find two numbers from their sum and XOR | C # program to find two numbers with given Sum and XOR such that value of first number is minimum . ; Function that takes in the sum and XOR of two numbers and generates the two numbers such that the value of X is minimized ; Traverse through all bits ; Let us leave bits as 0. ; We leave i - th bit of b as 0. ; else ( Xi == 1 && Ai == 1 ) ; Driver function"
Solution in C#:

using System ; public class GFG { static void compute ( long S , long X ) { long A = ( S - X ) / 2 ; int a = 0 , b = 0 ; for ( int i = 0 ; i < 8 * sizeof ( long ) ; i ++ ) { long Xi = ( X & ( 1 << i ) ) ; long Ai = ( A & ( 1 << i ) ) ; if ( Xi == 0 && Ai == 0 ) { } else if ( Xi == 0 && Ai > 0 ) { a = ( ( 1 << i ) a ) ; b = ( ( 1 << i ) b ) ; } else if ( Xi > 0 && Ai == 0 ) { a = ( ( 1 << i ) a ) ; } { Console . WriteLine ( " Not ▁ Possible " ) ; return ; } } Console . WriteLine ( " a ▁ = ▁ " + a + " b = " } public static void ( ) { long S = 17 , X = 13 ; compute ( S , X ) ; } }


"Find two numbers made up of a given digit such that their difference is divisible by N | C # implementation of the above approach ; Function to implement the above approach ; To store remainder - length of the number as key - value pairs ; Iterate till N + 1 length ; Search remainder in the map ; If remainder is not already present insert the length for the corresponding remainder ; Keep increasing M ; To keep M in range of integer ; Length of one number is the current Length ; Length of the other number is the length paired with current remainder in map ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static void findNumbers ( int N , int M ) { int m = M ; Dictionary < int , int > remLen = new Dictionary < int , int > ( ) ; int len , remainder = 0 ; for ( len = 1 ; len <= N + 1 ; ++ len ) { remainder = M % N ; if ( ! remLen . ContainsKey ( remainder ) ) { remLen . Add ( remainder , len ) ; } else { break ; } M = M * 10 + m ; M = M % N ; } int LenA = len ; int LenB = remLen [ remainder ] ; for ( int i = 0 ; i < LenB ; ++ i ) Console . Write ( m ) ; Console . Write ( " ▁ " ) ; for ( int i = 0 ; i < LenA ; ++ i ) Console . Write ( m ) ; } public static void Main ( String [ ] args ) { int N = 8 , M = 2 ; findNumbers ( N , M ) ; } }


"Find two numbers such that difference of their squares equal to N | C # Program to find two numbers with difference of their squares equal to N ; Function to check and print the required two positive integers ; Iterate till sqrt ( n ) to find factors of N ; Check if x is one of the factors of N ; Store the factor ; Compute the other factor ; Check if the two factors are of the same parity ; Compute a and b ; If no pair exists ; Driver Code"
Solution in C#:

using System ; class GFG { static void solve ( int n ) { for ( int x = 1 ; x <= Math . Sqrt ( n ) ; x ++ ) { if ( n % x == 0 ) { int small = x ; int big = n / x ; if ( small % 2 == big % 2 ) { int a = ( small + big ) / 2 ; int b = ( big - small ) / 2 ; Console . WriteLine ( a + " ▁ " + b ) ; return ; } } } Console . WriteLine ( - 1 ) ; } public static void Main ( ) { int n = 7 ; solve ( n ) ; } }


"Find two numbers whose difference of fourth power is equal to N | C # implementation to find the values of x and y for the given equation with integer N ; Function which find required x & y ; Upper limit of x & y , if such x & y exists ; num1 stores x ^ 4 ; num2 stores y ^ 4 ; If condition is satisfied the print and return ; If no such pair exists ; Driver code"
Solution in C#:

using System ; class GFG { static void solve ( int n ) { int upper_limit = ( int ) ( Math . Ceiling ( Math . Pow ( n , 1.0 / 4 ) ) ) ; for ( int x = 0 ; x <= upper_limit ; x ++ ) { for ( int y = 0 ; y <= upper_limit ; y ++ ) { int num1 = x * x * x * x ; int num2 = y * y * y * y ; if ( num1 - num2 == n ) { Console . Write ( " x ▁ = ▁ " + x + " , ▁ y ▁ = ▁ " + y ) ; return ; } } } Console . Write ( - 1 ) ; } public static void Main ( String [ ] args ) { int n = 15 ; solve ( n ) ; } }


"Find two numbers whose sum and GCD are given | C # program to find two numbers whose sum and GCD is given ; function to find gcd of two numbers ; Function to find two numbers whose sum and gcd is given ; sum != gcd checks that both the numbers are positive or not ; Driver code"
Solution in C#:

using System ; class GFG { static int __gcd ( int a , int b ) { if ( b == 0 ) return a ; return __gcd ( b , a % b ) ; } static void findTwoNumbers ( int sum , int gcd ) { if ( __gcd ( gcd , sum - gcd ) == gcd && sum != gcd ) Console . WriteLine ( " a ▁ = ▁ " + Math . Min ( gcd , sum - gcd ) + " , ▁ b ▁ = ▁ " + ( int ) ( sum - Math . Min ( gcd , sum - gcd ) ) ) ; else Console . WriteLine ( - 1 ) ; } public static void Main ( ) { int sum = 8 ; int gcd = 2 ; findTwoNumbers ( sum , gcd ) ; } }


"Find two numbers whose sum is N and does not contain any digit as K | C # program for the above approach ; Function to find two numbers whose sum is N and do not contain any digit as k ; Check every number i and ( n - i ) ; Check if i and n - i doesn 't  contain k in them print i and n-i ; Check if flag is 0 then print - 1 ; Driver code ; Given N and K ; Function call"
Solution in C#:

using System ; class GFG { static int freqCount ( String str , char k ) { int count = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == k ) count ++ ; } return count ; } static void findAandB ( int n , int k ) { int flag = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( freqCount ( i . ToString ( ) , ( char ) ( k + 48 ) ) == 0 && freqCount ( ( n - i ) . ToString ( ) , ( char ) ( k + 48 ) ) == 0 ) { Console . Write ( " ( " + i + " , ▁ " + ( n - i ) + " ) " ) ; flag = 1 ; break ; } } if ( flag == 0 ) Console . Write ( - 1 ) ; } public static void Main ( String [ ] args ) { int N = 100 ; int K = 0 ; findAandB ( N , K ) ; } }


"Find two numbers with difference and division both same as N | C # program for the above approach ; Function to find two numbers with difference and division both as N ; Condition if the answer is not possible ; Calculate a and b ; Print the values ; Driver Code ; Given N ; Function call"
Solution in C#:

 using System ; class GFG { static void findAandB ( double N ) { if ( N == 1 ) { Console . Write ( " No " ) ; return ; } double a = N * N / ( N - 1 ) ; double b = a / N ; Console . Write ( " a ▁ = ▁ " + a + "
 " ) ; Console . Write ( " b ▁ = ▁ " + b + "
 " ) ; } public static void Main ( String [ ] args ) { double N = 6 ; findAandB ( N ) ; } }


"Find two numbers with given sum and maximum possible LCM | C # program of the above approach ; Function that print two numbers with the sum X and maximum possible LCM ; Variables to store the result ; If X is odd ; If X is even ; If floor ( X / 2 ) is even ; If floor ( X / 2 ) is odd ; Print the result ; Driver code ; Given number ; Function call"
Solution in C#:

using System ; class GFG { static void maxLCMWithGivenSum ( int X ) { int A , B ; if ( ( X & 1 ) == 1 ) { A = X / 2 ; B = X / 2 + 1 ; } else { if ( ( X / 2 ) % 2 == 0 ) { A = X / 2 - 1 ; B = X / 2 + 1 ; } else { A = X / 2 - 2 ; B = X / 2 + 2 ; } } Console . WriteLine ( A + " ▁ " + B ) ; } public static void Main ( String [ ] args ) { int X = 30 ; maxLCMWithGivenSum ( X ) ; } }


"Find two numbers with sum N such that neither of them contains digit K | C # implementation of the above approach ; Count leading zeros ; It removes i characters starting from index 0 ; Check each digit of the N ; If digit is K break it ; For odd numbers ; Add D1 to A and D2 to B ; If the digit is not K , no need to break String D in A and 0 in B ; Remove leading zeros ; Print the answer ; Driver code"
Solution in C#:

 using System ; class GFG { static String removeLeadingZeros ( String str ) { int i = 0 ; int n = str . Length ; while ( str [ i ] == '0' && i < n ) i ++ ; str = str . Substring ( i ) ; return str ; } static void findPairs ( int sum , int K ) { String A , B ; A = " " ; B = " " ; String N = String . Join ( " " , sum ) ; int n = N . Length ; for ( int i = 0 ; i < n ; i ++ ) { int D = N [ i ] - '0' ; if ( D == K ) { int D1 , D2 ; D1 = D / 2 ; D2 = D / 2 + D % 2 ; A = A + ( char ) ( D1 + '0' ) ; B = B + ( char ) ( D2 + '0' ) ; } else { A = A + ( char ) ( D + '0' ) ; B = B + '0' ; } } A = removeLeadingZeros ( A ) ; B = removeLeadingZeros ( B ) ; Console . Write ( A + " , ▁ " + B + "
 " ) ; } public static void Main ( String [ ] args ) { int N = 33673 ; int K = 3 ; findPairs ( N , K ) ; } }


"Find two numbers with sum and product both same as N | C # program to find a and b such that a * b = N and a + b = N ; Function to return the smallest string ; Not possible ; find a and b ; Driver Code"
Solution in C#:

using System ; class GFG { static void findAandB ( double N ) { double val = N * N - 4.0 * N ; if ( val < 0 ) { Console . WriteLine ( " NO " ) ; return ; } double a = ( N + Math . Sqrt ( val ) ) / 2.0 ; double b = ( N - Math . Sqrt ( val ) ) / 2.0 ; Console . WriteLine ( " a ▁ = ▁ " + a ) ; Console . WriteLine ( " b ▁ = ▁ " + b ) ; } static void Main ( ) { double N = 69.0 ; findAandB ( N ) ; } }


"Find two numbers with the given LCM and minimum possible difference | C # implementation of the approach ; Function to return the LCM of a and b ; Function to find and print the two numbers ; To find the factors ; To check if i is a factor of x and the minimum possible number satisfying the given conditions ; Driver code"
Solution in C#:

using System ; class GFG { static int lcm ( int a , int b ) { return ( a / __gcd ( a , b ) * b ) ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static void findNums ( int x ) { int ans = - 1 ; for ( int i = 1 ; i <= Math . Sqrt ( x ) ; i ++ ) { if ( x % i == 0 && lcm ( i , x / i ) == x ) { ans = i ; } } Console . Write ( ans + " ▁ " + ( x / ans ) ) ; } public static void Main ( String [ ] args ) { int x = 12 ; findNums ( x ) ; } }


"Find two prime numbers with given sum | C # program to find a prime number pair whose sum is equal to given number C # program to print super primes less than or equal to n . ; Generate all prime numbers less than n . ; Initialize all entries of boolean array as true . A value in isPrime [ i ] will finally be false if i is Not a prime , else true bool isPrime [ n + 1 ] ; ; If isPrime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Prints a prime pair with given sum ; Generating primes using Sieve ; Traversing all numbers to find first pair ; Driver code"
Solution in C#:

using System ; class GFG { static bool SieveOfEratosthenes ( int n , bool [ ] isPrime ) { isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( int i = 2 ; i <= n ; i ++ ) isPrime [ i ] = true ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( isPrime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) isPrime [ i ] = false ; } } return false ; } static void findPrimePair ( int n ) { bool [ ] isPrime = new bool [ n + 1 ] ; SieveOfEratosthenes ( n , isPrime ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( isPrime [ i ] && isPrime [ n - i ] ) { Console . Write ( i + " ▁ " + ( n - i ) ) ; return ; } } } public static void Main ( ) { int n = 74 ; findPrimePair ( n ) ; } }


"Find two proper factors of N such that their sum is coprime with N | C # Program for the above approach ; Function to find two proper factors of N such that their sum is coprime with N ; Find factors in sorted order ; Find largest value of d2 such that d1 and d2 are co - prime ; Check if d1 and d2 are proper factors of N ; Print answer ; No such factors exist ; Driver code ; Function Call"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static void printFactors ( int n ) { for ( int i = 2 ; i <= ( int ) Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { int d1 = i , d2 = n ; while ( d2 % d1 == 0 ) { d2 = d2 / d1 ; } if ( d1 > 1 && d2 > 1 ) { Console . Write ( d1 + " , ▁ " + d2 ) ; return ; } } } Console . Write ( - 1 ) ; } public static void Main ( ) { int N = 10 ; printFactors ( N ) ; } }


"Find two vertices of an isosceles triangle in which there is rectangle with opposite corners ( 0 , 0 ) and ( X , Y ) | C # program to find two vertices of an isosceles triangle in which there is rectangle with opposite side ( 0 , 0 ) and ( x , y ) ; Function to find two vertices of an isosceles triangle in which there is rectangle with opposite side ( 0 , 0 ) and ( x , y ) ; Required value ; ; print x1 and y1 ; print x2 and y3 ; Driver code ; Function call"
Solution in C#:

using System ; class GFG { static void Vertices ( int x , int y ) { int val = Math . Abs ( x ) + Math . Abs ( y ) ; Console . Write ( val * ( x < 0 ? - 1 : 1 ) + " ▁ 0 ▁ " ) ; Console . Write ( "0 ▁ " + val * ( y < 0 ? - 1 : 1 ) ) ; } public static void Main ( String [ ] args ) { int x = 3 , y = 3 ; Vertices ( x , y ) ; } }


"Find uncommon characters of the two strings | C # implementation to find the uncommon characters of the two strings ; size of the hash table ; function to find the uncommon characters of the two strings ; mark presence of each character as 0 in the hash table ' present [ ] ' ; for each character of str1 , mark its presence as 1 in ' present [ ] ' ; for each character of str2 ; if a character of str2 is also present in str1 , then mark its presence as - 1 ; else mark its presence as 2 ; print all the uncommon characters ; Driver code"
Solution in C#:

using System ; class GFG { static int MAX_CHAR = 26 ; static void findAndPrintUncommonChars ( String str1 , String str2 ) { int [ ] present = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { present [ i ] = 0 ; } int l1 = str1 . Length ; int l2 = str2 . Length ; for ( int i = 0 ; i < l1 ; i ++ ) { present [ str1 [ i ] - ' a ' ] = 1 ; } for ( int i = 0 ; i < l2 ; i ++ ) { if ( present [ str2 [ i ] - ' a ' ] == 1 present [ str2 [ i ] - ' a ' ] == - 1 ) { present [ str2 [ i ] - ' a ' ] = - 1 ; } else { present [ str2 [ i ] - ' a ' ] = 2 ; } } for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( present [ i ] == 1 present [ i ] == 2 ) { Console . Write ( ( char ) ( i + ' a ' ) + " ▁ " ) ; } } } public static void Main ( String [ ] args ) { String str1 = " characters " ; String str2 = " alphabets " ; findAndPrintUncommonChars ( str1 , str2 ) ; } }


"Find unique pairs such that each element is less than or equal to N | C # program for finding the required pairs ; Finding the number of unique pairs ; Using the derived formula ; Printing the unique pairs ; Driver code"
Solution in C#:

using System ; class GFG { static int No_Of_Pairs ( int N ) { int i = 1 ; while ( ( i * i * i ) + ( 2 * i * i ) + i <= N ) i ++ ; return ( i - 1 ) ; } static void print_pairs ( int pairs ) { int i = 1 , mul ; for ( i = 1 ; i <= pairs ; i ++ ) { mul = i * ( i + 1 ) ; Console . WriteLine ( " Pair ▁ no . ▁ " + i + " ▁ - - > ▁ ( " + ( mul * i ) + " , ▁ " + mul * ( i + 1 ) + " ) " ) ; } } static void Main ( ) { int N = 500 , pairs ; pairs = No_Of_Pairs ( N ) ; Console . WriteLine ( " No . ▁ of ▁ pairs ▁ = ▁ " + pairs ) ; print_pairs ( pairs ) ; } }


"Find unit digit of x raised to power y | C # code to find the unit digit of x raised to power y . ; find unit digit ; Get last digit of x ; Last cyclic modular value ; here we simply return the unit digit or the power of a number ; Driver code ; get unit digit number here we pass the unit digit of x and the last cyclicity number that is y % 4"
Solution in C#:

using System ; class GFG { static int unitnumber ( int x , int y ) { x = x % 10 ; if ( y != 0 ) y = y % 4 + 4 ; return ( ( ( int ) ( Math . Pow ( x , y ) ) ) % 10 ) ; } public static void Main ( ) { int x = 133 , y = 5 ; Console . WriteLine ( unitnumber ( x , y ) ) ; } }


"Find unit digit of x raised to power y | Efficient Java program to find unit digit of x ^ y . ; Returns unit digit of x raised to power y ; Initialize result as 1 to handle case when y is 0. ; One by one multiply with x mod 10 to avoid overflow . ; Driver program"
Solution in C#:

using System ; class GFG { static int unitDigitXRaisedY ( int x , int y ) { int res = 1 ; for ( int i = 0 ; i < y ; i ++ ) res = ( res * x ) % 10 ; return res ; } public static void Main ( ) { Console . WriteLine ( unitDigitXRaisedY ( 4 , 2 ) ) ; } }


"Find value K in given Complete Binary Tree with values indexed from 1 to N | C # program for the above approach ; Class containing left and right child of current node and key value ; Function to store the list of the directions ; While the root is not found ; If it is the right child of its parent ; Add right step ( 1 ) ; Add left step ( - 1 ) ; Repeat the same for its parent ; Reverse the steps list ; Return the steps ; Function to find if the key is present or not ; Get the steps to be followed ; Taking one step at a time ; Go left ; If left child does not exist return false ; Go right ; If right child does not exist return false ; If the entire array of steps has been successfully traversed ; Consider the following complete binary tree 1 / \ 2 3 / \ / \ 4 5 6 7 / \ / 8 9 10 ; Function Call"
Solution in C#:

using System ; using System . Collections . Generic ; class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class Solution { public static List < int > findSteps ( Node root , int data ) { List < int > steps = new List < int > ( ) ; while ( data != 1 ) { if ( data / 2.0 > data / 2 ) { steps . Add ( 1 ) ; } else { steps . Add ( - 1 ) ; } int parent = data / 2 ; data = parent ; } steps . Reverse ( ) ; return steps ; } public static bool findKey ( Node root , int data ) { List < int > steps = findSteps ( root , data ) ; foreach ( int cur_step in steps ) { if ( cur_step == - 1 ) { if ( root . left == null ) return false ; root = root . left ; } else { if ( root . right == null ) return false ; root = root . right ; } } return true ; } public static void Main ( ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; root . left . left . left = new Node ( 8 ) ; root . left . left . right = new Node ( 9 ) ; root . left . right . left = new Node ( 10 ) ; Console . Write ( findKey ( root , 7 ) ) ; } }


"Find value after N operations to remove N characters of string S with given constraints | C # program for the above approach ; Function to find the value after N operations to remove all the N characters of String S ; Iterate till N ; Remove character at ind and decrease n ( size of String ) ; Increase count by ind + 1 ; Driver Code ; Given String str ; Function call"
Solution in C#:

 using System ; class GFG { static void charactersCount ( String str , int n ) { int count = 0 ; while ( n > 0 ) { char cur = str [ 0 ] ; int ind = 0 ; for ( int j = 1 ; j < n ; j ++ ) { if ( str [ j ] < cur ) { cur = str [ j ] ; ind = j ; } } str = str . Substring ( 0 , ind ) + str . Substring ( ind + 1 ) ; n -- ; count += ind + 1 ; } Console . Write ( count + "
 " ) ; } public static void Main ( String [ ] args ) { String str = " aabbc " ; int n = 5 ; charactersCount ( str , n ) ; } }


"Find value of ( n ^ 1 + n ^ 2 + n ^ 3 + n ^ 4 ) mod 5 for given n | Code for finding the value of f ( n ) mod 5 for given n . ; function for f ( n ) mod 5 ; if n % 5 == 1 return 4 ; else return 0 ; Driver program"
Solution in C#:

using System ; class GFG { static int fnMod ( int n ) { if ( n % 5 == 1 ) return 4 ; else return 0 ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( fnMod ( n ) ) ; n = 11 ; Console . WriteLine ( fnMod ( n ) ) ; } }


"Find value of k | C # program to find k - th bit from right ; Driver Code ; Function Call"
Solution in C#:

using System ; class GFG { static void printKthBit ( long n , long k ) { Console . WriteLine ( ( n & ( 1 << ( k - 1 ) ) ) >> ( k - 1 ) ) ; } public static void Main ( ) { long n = 13 , k = 2 ; printKthBit ( n , k ) ; } }


"Find ways an Integer can be expressed as sum of n | C # program to count number of ways any given integer x can be expressed as n - th power of unique natural numbers . ; Function to calculate and return the power of any given number ; Function to check power representations recursively ; Initialize number of ways to express x as n - th powers of different natural numbers ; Calling power of ' i ' raised to ' n ' ; Recursively check all greater values of i ; If sum of powers is equal to x then increase the value of result . ; Return the final result ; Driver Code ."
Solution in C#:

using System ; class GFG { static int power ( int num , int n ) { if ( n == 0 ) return 1 ; else if ( n % 2 == 0 ) return power ( num , n / 2 ) * power ( num , n / 2 ) ; else return num * power ( num , n / 2 ) * power ( num , n / 2 ) ; } static int checkRecursive ( int x , int n , int curr_num , int curr_sum ) { int results = 0 ; int p = power ( curr_num , n ) ; while ( p + curr_sum < x ) { results += checkRecursive ( x , n , curr_num + 1 , p + curr_sum ) ; curr_num ++ ; p = power ( curr_num , n ) ; } if ( p + curr_sum == x ) results ++ ; return results ; } public static void Main ( ) { int x = 10 , n = 2 ; System . Console . WriteLine ( checkRecursive ( x , n , 1 , 0 ) ) ; } }


"Find ways an Integer can be expressed as sum of n | C # program to find number of ways to express a number as sum of n - th powers of numbers . ; Wrapper over checkRecursive ( ) ; Driver code"
Solution in C#:

using System ; class Solution { static int res = 0 ; static int checkRecursive ( int num , int x , int k , int n ) { if ( x == 0 ) res ++ ; int r = ( int ) Math . Floor ( Math . Pow ( num , 1.0 / n ) ) ; for ( int i = k + 1 ; i <= r ; i ++ ) { int a = x - ( int ) Math . Pow ( i , n ) ; if ( a >= 0 ) checkRecursive ( num , x - ( int ) Math . Pow ( i , n ) , i , n ) ; } return res ; } static int check ( int x , int n ) { return checkRecursive ( x , x , 0 , n ) ; } public static void Main ( ) { Console . WriteLine ( check ( 10 , 2 ) ) ; } }


"Find ways to arrange K green balls among N balls such that exactly i moves is needed to collect all K green balls | C # implementation of the approach ; To store the factorial and the factorial mod inverse of a number ; Function to find ( a ^ m1 ) % mod ; Function to find factorial of all the numbers ; Function to find the factorial mod inverse of all the numbers ; Function to return nCr ; Function to find ways to arrange K green balls among N balls such that we need exactly i moves to collect all K green balls ; Driver code ; Function call"
Solution in C#:

using System ; class GFG { static readonly int N = 100005 ; static readonly int mod = ( int ) ( 1e9 + 7 ) ; static long [ ] factorial = new long [ N ] ; static long [ ] modinverse = new long [ N ] ; static long power ( long a , int m1 ) { if ( m1 == 0 ) return 1 ; else if ( m1 == 1 ) return a ; else if ( m1 == 2 ) return ( 1L * a * a ) % mod ; else if ( m1 % 2 == 1 ) return ( 1L * a * power ( power ( a , m1 / 2 ) , 2 ) ) % mod ; else return power ( power ( a , m1 / 2 ) , 2 ) % mod ; } static void factorialfun ( ) { factorial [ 0 ] = 1 ; for ( int i = 1 ; i < N ; i ++ ) factorial [ i ] = ( 1L * factorial [ i - 1 ] * i ) % mod ; } static void modinversefun ( ) { modinverse [ N - 1 ] = ( int ) ( power ( factorial [ N - 1 ] , mod - 2 ) % mod ) ; for ( int i = N - 2 ; i >= 0 ; i -- ) modinverse [ i ] = ( 1 * modinverse [ i + 1 ] * ( i + 1 ) ) % mod ; } static long binomial ( int n , int r ) { if ( r > n ) return 0 ; long a = ( 1L * factorial [ n ] * modinverse [ n - r ] ) % mod ; a = ( 1 * a * modinverse [ r ] ) % mod ; return a ; } static void arrange_balls ( int n , int k ) { factorialfun ( ) ; modinversefun ( ) ; for ( int i = 1 ; i <= k ; i ++ ) Console . Write ( ( 1L * binomial ( n - k + 1 , i ) * binomial ( k - 1 , i - 1 ) ) % mod + " ▁ " ) ; } public static void Main ( String [ ] args ) { int n = 5 , k = 3 ; arrange_balls ( n , k ) ; } }


"Find whether X exists in Y after jumbling X | C # implementation of the approach ; Function that returns true if both the arrays have equal values ; Test the equality ; Function that returns true if any permutation of X exists as a subString in Y ; Base case ; To store cumulative frequency ; Finding the frequency of characters in X ; Finding the frequency of characters in Y upto the length of X ; Equality check ; Two pointer approach to generate the entire cumulative frequency ; Remove the first character of the previous window ; Add the last character of the current window ; Equality check ; Driver code"
Solution in C#:

using System ; class GFG { static int MAX = 26 ; static bool areEqual ( int [ ] a , int [ ] b ) { for ( int i = 0 ; i < MAX ; i ++ ) if ( a [ i ] != b [ i ] ) return false ; return true ; } static bool xExistsInY ( String x , String y ) { if ( x . Length > y . Length ) return false ; int [ ] cnt_x = new int [ MAX ] ; int [ ] cnt = new int [ MAX ] ; for ( int i = 0 ; i < x . Length ; i ++ ) cnt_x [ x [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < x . Length ; i ++ ) cnt [ y [ i ] - ' a ' ] ++ ; if ( areEqual ( cnt_x , cnt ) ) return true ; for ( int i = 1 ; i < y . Length - x . Length + 1 ; i ++ ) { cnt [ y [ i - 1 ] - ' a ' ] -- ; cnt [ y [ i + x . Length - 1 ] - ' a ' ] ++ ; if ( areEqual ( cnt , cnt_x ) ) return true ; } return false ; } public static void Main ( String [ ] args ) { String x = " skege " ; String y = " geeksforgeeks " ; if ( xExistsInY ( x , y ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }


"Find whether a given integer is a power of 3 or not | C # program to check if a number is power of 3 or not . ; Returns true if n is power of 3 , else false ; The maximum power of 3 value that integer can hold is 1162261467 ( 3 ^ 19 ) . ; Driver code"
Solution in C#:

using System ; public class GFG { static bool check ( int n ) { if ( n <= 0 ) return false ; return 1162261467 % n == 0 ; } public static void Main ( ) { int n = 9 ; if ( check ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }


"Find whether a given number is a power of 4 or not | C # code to check if given number is power of 4 or not ; Function to check if x is power of 4 ; Driver code"
Solution in C#:

using System ; class GFG { static int isPowerOfFour ( int n ) { if ( n == 0 ) return 0 ; while ( n != 1 ) { if ( n % 4 != 0 ) return 0 ; n = n / 4 ; } return 1 ; } public static void Main ( ) { int test_no = 64 ; if ( isPowerOfFour ( test_no ) == 1 ) Console . Write ( test_no + " ▁ is ▁ a ▁ power ▁ of ▁ 4" ) ; else Console . Write ( test_no + " ▁ is ▁ not ▁ a ▁ power ▁ of ▁ 4" ) ; } }


"Find whether a given number is a power of 4 or not | C # program to check if given number is power of 4 or not ; 0 is not considered as a power of 4 ; Driver code"
Solution in C#:

using System ; class GFG { static double logn ( int n , int r ) { return Math . Log ( n ) / Math . Log ( r ) ; } static bool isPowerOfFour ( int n ) { if ( n == 0 ) return false ; return Math . Floor ( logn ( n , 4 ) ) == Math . Ceiling ( logn ( n , 4 ) ) ; } public static void Main ( String [ ] args ) { int test_no = 64 ; if ( isPowerOfFour ( test_no ) ) Console . Write ( test_no + " ▁ is ▁ a ▁ power ▁ of ▁ 4" ) ; else Console . Write ( test_no + " ▁ is ▁ not ▁ a ▁ power ▁ of ▁ 4" ) ; } }


"Find whether a given number is a power of 4 or not | C # program to check if given number is power of 4 or not ; Driver Code"
Solution in C#:

using System ; class GFG { static bool isPowerOfFour ( int n ) { return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) && ( n & 0xAAAAAAAA ) == 0 ; } static void Main ( ) { int test_no = 64 ; if ( isPowerOfFour ( test_no ) ) Console . WriteLine ( " { 0 } ▁ is ▁ a ▁ power ▁ of ▁ 4" , test_no ) ; else Console . WriteLine ( " { 0 } ▁ is ▁ not ▁ a ▁ power ▁ of ▁ 4" , test_no ) ; } }


"Find whether a given number is a power of 4 or not | C # program to check if given number is power of 4 or not ; Function to check if x is power of 4 ; Check if there is only one bit set in n ; count 0 bits before set bit ; If count is even then return true else false ; If there are more than 1 bit set then n is not a power of 4 ; Driver program to test above function"
Solution in C#:

using System ; class GFG { static int isPowerOfFour ( int n ) { int count = 0 ; int x = n & ( n - 1 ) ; if ( n > 0 && x == 0 ) { while ( n > 1 ) { n >>= 1 ; count += 1 ; } return ( count % 2 == 0 ) ? 1 : 0 ; } return 0 ; } static void Main ( ) { int test_no = 64 ; if ( isPowerOfFour ( test_no ) > 0 ) Console . WriteLine ( " { 0 } ▁ is ▁ a ▁ power ▁ of ▁ 4" , test_no ) ; else Console . WriteLine ( " { 0 } ▁ is ▁ not ▁ a ▁ power ▁ of ▁ 4" , test_no ) ; } }


"Find whether a subarray is in form of a mountain or not | C # program to check whether a subarray is in mountain form or not ; Utility method to construct left and right array ; initialize first left index as that index only ; if current value is greater than previous , update last increasing ; initialize last right index as that index only ; if current value is greater than next , update first decreasing ; method returns true if arr [ L . . R ] is in mountain form ; return true only if right at starting range is greater than left at ending range ; Driver Code"
Solution in C#:

using System ; class GFG { static void preprocess ( int [ ] arr , int N , int [ ] left , int [ ] right ) { left [ 0 ] = 0 ; int lastIncr = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) lastIncr = i ; left [ i ] = lastIncr ; } right [ N - 1 ] = N - 1 ; int firstDecr = N - 1 ; for ( int i = N - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > arr [ i + 1 ] ) firstDecr = i ; right [ i ] = firstDecr ; } } static bool isSubarrayMountainForm ( int [ ] arr , int [ ] left , int [ ] right , int L , int R ) { return ( right [ L ] >= left [ R ] ) ; } static public void Main ( ) { int [ ] arr = { 2 , 3 , 2 , 4 , 4 , 6 , 3 , 2 } ; int N = arr . Length ; int [ ] left = new int [ N ] ; int [ ] right = new int [ N ] ; preprocess ( arr , N , left , right ) ; int L = 0 ; int R = 2 ; if ( isSubarrayMountainForm ( arr , left , right , L , R ) ) Console . WriteLine ( " Subarray ▁ is ▁ in ▁ " + " mountain ▁ form " ) ; else Console . WriteLine ( " Subarray ▁ is ▁ not ▁ " + " in ▁ mountain ▁ form " ) ; L = 1 ; R = 3 ; if ( isSubarrayMountainForm ( arr , left , right , L , R ) ) Console . WriteLine ( " Subarray ▁ is ▁ in ▁ " + " mountain ▁ form " ) ; else Console . WriteLine ( " Subarray ▁ is ▁ not ▁ " + " in ▁ mountain ▁ form " ) ; } }


"Find whether only two parallel lines contain all coordinates points or not | C # implementation of the above approach ; Find if slope is good with only two intercept ; if set of lines have only two distinct intercept ; Function to check if required solution exist ; check the result by processing the slope by starting three points ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class GfG { static bool isSlopeGood ( double slope , int [ ] arr , int n ) { HashSet < Double > setOfLines = new HashSet < Double > ( ) ; for ( int i = 0 ; i < n ; i ++ ) setOfLines . Add ( arr [ i ] - slope * ( i ) ) ; return setOfLines . Count == 2 ; } static bool checkForParallel ( int [ ] arr , int n ) { bool slope1 = isSlopeGood ( arr [ 1 ] - arr [ 0 ] , arr , n ) ; bool slope2 = isSlopeGood ( arr [ 2 ] - arr [ 1 ] , arr , n ) ; bool slope3 = isSlopeGood ( ( arr [ 2 ] - arr [ 0 ] ) / 2 , arr , n ) ; return ( slope1 == true slope2 == true slope3 == true ) ; } public static void Main ( ) { int [ ] arr = { 1 , 6 , 3 , 8 , 5 } ; int n = arr . Length ; if ( checkForParallel ( arr , n ) == true ) Console . WriteLine ( "1" ) ; else Console . WriteLine ( "0" ) ; } }


"Find winner in game of N balls , in which a player can remove any balls in range [ A , B ] in a single move | C # program of the above approach ; Function to find the winner of the game ; Stores sum of A and B ; If N is of the form m * ( A + B ) + y ; Otherwise , ; Driver code ; Input ; Function call"
Solution in C#:

using System ; class GFG { public static String NimGame ( int N , int A , int B ) { int sum = A + B ; if ( N % sum <= A - 1 ) return " Bob " ; else return " Alice " ; } static void Main ( ) { int N = 3 , A = 1 , B = 2 ; Console . Write ( NimGame ( N , A , B ) ) ; } }


"Find winner of an election where votes are represented as candidate names | C # program to find winner in an election . ; We have four Candidates with name as ' John ' , ' Johnny ' , ' jamie ' , ' jackie ' . The votes in String array are as per the votes casted . Print the name of candidates received Max vote . ; Insert all votes in a hashmap ; Traverse through map to find the candidate with maximum votes . ; If there is a tie , pick lexicographically smaller . ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; public class ElectoralVotingBallot { public static void findWinner ( String [ ] votes ) { Dictionary < String , int > map = new Dictionary < String , int > ( ) ; foreach ( String str in votes ) { if ( map . ContainsKey ( str ) ) map [ str ] = map [ str ] + 1 ; else map . Add ( str , 1 ) ; } int maxValueInMap = 0 ; String winner = " " ; foreach ( KeyValuePair < String , int > entry in map ) { String key = entry . Key ; int val = entry . Value ; if ( val > maxValueInMap ) { maxValueInMap = val ; winner = key ; } else if ( val == maxValueInMap && winner . CompareTo ( key ) > 0 ) winner = key ; } Console . WriteLine ( winner ) ; } public static void Main ( String [ ] args ) { String [ ] votes = { " john " , " johnny " , " jackie " , " johnny " , " john " , " jackie " , " jamie " , " jamie " , " john " , " johnny " , " jamie " , " johnny " , " john " } ; findWinner ( votes ) ; } }


"Find x , y , z that satisfy 2 / n = 1 / x + 1 / y + 1 / z | C # program to find x y z that satisfies 2 / n = 1 / x + 1 / y + 1 / z ... ; function to find x y and z that satisfy given equation . ; Driver program"
Solution in C#:

using System ; class GFG { static void printXYZ ( int n ) { if ( n == 1 ) Console . WriteLine ( - 1 ) ; else { Console . WriteLine ( " x ▁ is ▁ " + n ) ; Console . WriteLine ( " y ▁ is ▁ " + ( n + 1 ) ) ; Console . WriteLine ( " z ▁ is ▁ " + ( n * ( n + 1 ) ) ) ; } } public static void Main ( ) { int n = 7 ; printXYZ ( n ) ; } }


"Find x and y satisfying ax + by = n | C # program to find solution of ax + by = n ; function to find the solution ; traverse for all possible values ; check if it is satisfying the equation ; Driver code"
Solution in C#:

using System ; class GfG { static void solution ( int a , int b , int n ) { for ( int i = 0 ; i * a <= n ; i ++ ) { if ( ( n - ( i * a ) ) % b == 0 ) { Console . Write ( " x ▁ = ▁ " + i + " , ▁ y ▁ = ▁ " + ( n - ( i * a ) ) / b ) ; return ; } } Console . Write ( " No ▁ solution " ) ; } public static void Main ( ) { int a = 2 , b = 3 , n = 7 ; solution ( a , b , n ) ; } }


"Find zeroes to be flipped so that number of consecutive 1 's is maximized | C # to find positions of zeroes flipping which produces maximum number of consecutive 1 's ; m is maximum of number zeroes allowed to flip ; Left and right indexes of current window ; Left index and size of the widest window ; Count of zeroes in current window ; While right boundary of current window doesn 't cross right end ; If zero count of current window is less than m , widen the window toward right ; If zero count of current window is more than m , reduce the window from left ; Update widest window if this window size is more ; Print positions of zeroes in the widest window ; Driver method to test the above function"
Solution in C#:

using System ; class Test { static int [ ] arr = new int [ ] { 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 1 } ; static void findZeroes ( int m ) { int wL = 0 , wR = 0 ; int bestL = 0 , bestWindow = 0 ; int zeroCount = 0 ; while ( wR < arr . Length ) { if ( zeroCount <= m ) { if ( arr [ wR ] == 0 ) zeroCount ++ ; wR ++ ; } if ( zeroCount > m ) { if ( arr [ wL ] == 0 ) zeroCount -- ; wL ++ ; } if ( ( wR - wL > bestWindow ) && ( zeroCount <= m ) ) { bestWindow = wR - wL ; bestL = wL ; } } for ( int i = 0 ; i < bestWindow ; i ++ ) { if ( arr [ bestL + i ] == 0 ) Console . Write ( bestL + i + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int m = 2 ; Console . Write ( " Indexes ▁ of ▁ zeroes ▁ to ▁ be ▁ flipped ▁ are ▁ " ) ; findZeroes ( m ) ; } }


"Finding ' k ' such that its modulus with each array element is same | C # implementation of finding all k such that arr [ i ] % k is same for each i ; Prints all k such that arr [ i ] % k is same for all i ; sort the numbers ; max difference will be the difference between first and last element of sorted array ; Case when all the array elements are same ; Find all divisors of d and store in a vector v [ ] ; check for each v [ i ] if its modulus with each array element is same or not ; checking for each array element if its modulus with k is equal to k or not ; if check is true print v [ i ] ; Driver method"
Solution in C#:

using System ; using System . Collections ; class Test { static void printEqualModNumbers ( int [ ] arr , int n ) { Array . Sort ( arr ) ; int d = arr [ n - 1 ] - arr [ 0 ] ; if ( d == 0 ) { Console . write ( " Infinite ▁ solution " ) ; return ; } ArrayList v = new ArrayList ( ) ; for ( int i = 1 ; i * i <= d ; i ++ ) { if ( d % i == 0 ) { v . Add ( i ) ; if ( i != d / i ) v . Add ( d / i ) ; } } for ( int i = 0 ; i < v . Count ; i ++ ) { int temp = arr [ 0 ] % ( int ) v [ i ] ; int j ; for ( j = 1 ; j < n ; j ++ ) if ( arr [ j ] % ( int ) v [ i ] != temp ) break ; if ( j == n ) Console . Write ( v [ i ] + " ▁ " ) ; } } public static void Main ( ) { int [ ] arr = { 38 , 6 , 34 } ; printEqualModNumbers ( arr , arr . Length ) ; } }


"Finding Astronauts from different countries | C # program for the above approach ; Function to perform the DFS Traversal to find the count of connected components ; Function to perform the DFS Traversal to find the count of connected components ; Marking vertex visited ; DFS call to neighbour vertices ; If the current node is not visited , then recursively call DFS ; Function to find the number of ways to choose two astronauts from the different countries ; Stores the Adjacency list ; Constructing the graph ; Stores the visited vertices ; Stores the size of every connected components ; DFS call to the graph ; Store size of every connected component ; Stores the total number of ways to count the pairs ; Traverse the array ; Print the value of ans ; Driver Code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static List < List < int > > adj ; static bool [ ] visited ; static int num ; static void dfs ( int v ) { visited [ v ] = true ; num ++ ; for ( int i = 0 ; i < adj [ v ] . Count ; i ++ ) { if ( ! visited [ adj [ v ] [ i ] ] ) { dfs ( adj [ v ] [ i ] ) ; } } } static void numberOfPairs ( int N , int [ , ] arr ) { adj = new List < List < int > > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { adj . Add ( new List < int > ( ) ) ; } for ( int i = 0 ; i < 2 ; i ++ ) { adj [ arr [ i , 0 ] ] . Add ( arr [ i , 1 ] ) ; adj [ arr [ i , 1 ] ] . Add ( arr [ i , 0 ] ) ; } visited = new bool [ N ] ; Array . Fill ( visited , false ) ; List < int > v = new List < int > ( ) ; num = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! visited [ i ] ) { dfs ( i ) ; v . Add ( num ) ; num = 0 ; } } int ans = N * ( N - 1 ) / 2 + 1 ; for ( int i = 0 ; i < v . Count ; i ++ ) { ans -= ( v [ i ] * ( v [ i ] - 1 ) / 2 ) + 1 ; } Console . Write ( ans ) ; } static void Main ( ) { int N = 6 ; int [ , ] arr = { { 0 , 1 } , { 0 , 2 } , { 2 , 5 } } ; numberOfPairs ( N , arr ) ; } }


"Finding Integreand using Weedle 's Rule | C # program to Implement Weedle 's Rule ; A sample function f ( x ) = 1 / ( 1 + x ^ 2 ) ; Function to find the integral value of f ( x ) with step size h , with initial lower limit and upper limit a and b ; Find step size h ; To store the final sum ; Find sum using Weedle 's Formula ; Return the final sum ; Driver Code ; lower limit and upper limit ; Function Call"
Solution in C#:

using System ; class GFG { static float y ( float x ) { float num = 1 ; float denom = ( float ) 1.0 + x * x ; return num / denom ; } static float WeedleRule ( float a , float b ) { float h = ( b - a ) / 6 ; float sum = 0 ; sum = sum + ( ( ( 3 * h ) / 10 ) * ( y ( a ) + y ( a + 2 * h ) + 5 * y ( a + h ) + 6 * y ( a + 3 * h ) + y ( a + 4 * h ) + 5 * y ( a + 5 * h ) + y ( a + 6 * h ) ) ) ; return sum ; } public static void Main ( ) { float a = 0 , b = 6 ; float num = WeedleRule ( a , b ) ; Console . Write ( " f ( x ) ▁ = ▁ " + num ) ; } }


"Finding Quadrant of a Coordinate with respect to a Circle | C # Program to find the quadrant of a given coordinate with respect to the centre of a circle ; Thus function returns the quadrant number ; Coincides with center ; Outside circle ; 1 st quadrant ; 2 nd quadrant ; 3 rd quadrant ; 4 th quadrant ; Driver Code ; Coordinates of centre ; Radius of circle ; Coordinates of the given point"
Solution in C#:

using System ; class GFG { static int getQuadrant ( int X , int Y , int R , int PX , int PY ) { if ( PX == X && PY == Y ) return 0 ; int val = ( int ) Math . Pow ( ( PX - X ) , 2 ) + ( int ) Math . Pow ( ( PY - Y ) , 2 ) ; if ( val > Math . Pow ( R , 2 ) ) return - 1 ; if ( PX > X && PY >= Y ) return 1 ; if ( PX <= X && PY > Y ) return 2 ; if ( PX < X && PY <= Y ) return 3 ; if ( PX >= X && PY < Y ) return 4 ; return 0 ; } public static void Main ( ) { int X = 0 , Y = 3 ; int R = 2 ; int PX = 1 , PY = 4 ; int ans = getQuadrant ( X , Y , R , PX , PY ) ; if ( ans == - 1 ) Console . WriteLine ( " Lies ▁ Outside " + " ▁ the ▁ circle " ) ; else if ( ans == 0 ) Console . WriteLine ( " Coincides ▁ " + " with ▁ centre " ) ; else Console . WriteLine ( ans + " ▁ Quadrant " ) ; } }


"Finding minimum vertex cover size of a graph using binary search | A C # program to find size of minimum vertex cover using Binary Search ; Global array to store the graph Note : since the array is global , all the elements are 0 initially ; Returns true if there is a possible subset of size ' k ' that can be a vertex cover ; Set has first ' k ' bits high initially ; to mark the edges covered in each subset of size ' k ' ; Reset visited array for every subset of vertices ; set counter for number of edges covered from this subset of vertices to zero ; selected vertex cover is the indices where ' set ' has its bit high ; Mark all edges emerging out of this vertex visited ; If the current subset covers all the edges ; Generate previous combination with k bits high set & - set = ( 1 << last bit high in set ) ; Returns answer to graph stored in gr [ , ] ; Binary search the answer ; at the end of while loop both left and right will be equal , / as when they are not , the while loop won 't exit the minimum  size vertex cover = left = right ; Inserts an edge in the graph ; Undirected graph ; Driver code ; 6 / 1 -- -- - 5 vertex cover = { 1 , 2 } / | \ 3 | \  \ | \ 2 4 ; Let us create another graph ; 2 -- -- 4 -- -- 6 / | | 1 | | vertex cover = { 2 , 3 , 4 } \ | | 3 -- -- 5"
Solution in C#:

 using System ; class GFG { static readonly int maxn = 25 ; static bool [ , ] gr = new bool [ maxn , maxn ] ; static bool isCover ( int V , int k , int E ) { int set = ( 1 << k ) - 1 ; int limit = ( 1 << V ) ; bool [ , ] vis = new bool [ maxn , maxn ] ; ; while ( set < limit ) { for ( int i = 0 ; i < maxn ; i ++ ) { for ( int j = 0 ; j < maxn ; j ++ ) { vis [ i , j ] = false ; } } int cnt = 0 ; for ( int j = 1 , v = 1 ; j < limit ; j = j << 1 , v ++ ) { if ( ( set & j ) != 0 ) { for ( int co = 1 ; co <= V ; co ++ ) { if ( gr [ v , co ] && ! vis [ v , co ] ) { vis [ v , co ] = true ; vis [ co , v ] = true ; cnt ++ ; } } } } if ( cnt == E ) return true ; int cO = set & - set ; int rO = set + cO ; set = ( ( ( rO ^ set ) >> 2 ) / cO ) | rO ; } return false ; } static int findMinCover ( int n , int m ) { int left = 1 , right = n ; while ( right > left ) { int mid = ( left + right ) >> 1 ; if ( isCover ( n , mid , m ) == false ) left = mid + 1 ; else right = mid ; } return left ; } static void insertEdge ( int u , int v ) { gr [ u , v ] = true ; gr [ v , u ] = true ; } public static void Main ( String [ ] args ) { int V = 6 , E = 6 ; insertEdge ( 1 , 2 ) ; insertEdge ( 2 , 3 ) ; insertEdge ( 1 , 3 ) ; insertEdge ( 1 , 4 ) ; insertEdge ( 1 , 5 ) ; insertEdge ( 1 , 6 ) ; Console . Write ( " Minimum ▁ size ▁ of ▁ a ▁ vertex ▁ cover ▁ = ▁ " + findMinCover ( V , E ) + "
 " ) ; for ( int i = 0 ; i < maxn ; i ++ ) { for ( int j = 0 ; j < maxn ; j ++ ) { gr [ i , j ] = false ; } } V = 6 ; E = 7 ; insertEdge ( 1 , 2 ) ; insertEdge ( 1 , 3 ) ; insertEdge ( 2 , 3 ) ; insertEdge ( 2 , 4 ) ; insertEdge ( 3 , 5 ) ; insertEdge ( 4 , 5 ) ; insertEdge ( 4 , 6 ) ; Console . Write ( " Minimum ▁ size ▁ of ▁ a ▁ vertex ▁ cover ▁ = ▁ " + findMinCover ( V , E ) + "
 " ) ; } }


"Finding n | A formula based C # program to find sum of series with cubes of first n natural numbers ; Driver Function"
Solution in C#:

using System ; class GFG { static int magicOfSequence ( int N ) { return ( N * ( N + 1 ) / 2 ) + 2 * N ; } public static void Main ( ) { int N = 6 ; Console . Write ( magicOfSequence ( N ) ) ; } }


"Finding n | C # Program to Finding n - th term of series 3 , 13 , 42 , 108 , 235 . . . ; Function to generate a fixed number ; Driver Code"
Solution in C#:

using System ; class GFG { public static int magicOfSequence ( int N ) { int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) sum += ( i * i * i + i * 2 ) ; return sum ; } static public void Main ( ) { int N = 4 ; Console . WriteLine ( magicOfSequence ( N ) ) ; } }


"Finding n | C # implementation for finding nth number made of prime digits only ; Prints n - th number where each digit is a prime number ; Finding the length of n - th number ; Count of numbers with len - 1 digits ; Count of numbers with i digits ; if i is the length of such number then n < 4 * ( 4 ^ ( i - 1 ) - 1 ) / 3 and n >= 4 * ( 4 ^ i - 1 ) / 3 if a valid i is found break the loop ; check for i + 1 ; Finding ith digit at ith place ; j = 1 means 2 j = 2 means ... j = 4 means 7 ; if prev_count + 4 ^ ( len - i ) is less than n , increase prev_count by 4 ^ ( x - i ) ; else print the ith digit and break ; Driver method"
Solution in C#:

using System ; public class GFG { static void nthprimedigitsnumber ( long n ) { long len = 1 ; long prev_count = 0 ; while ( true ) { long curr_count = ( long ) ( prev_count + Math . Pow ( 4 , len ) ) ; if ( prev_count < n && curr_count >= n ) break ; len ++ ; prev_count = curr_count ; } for ( int i = 1 ; i <= len ; i ++ ) { for ( long j = 1 ; j <= 4 ; j ++ ) { if ( prev_count + Math . Pow ( 4 , len - i ) < n ) prev_count += ( long ) Math . Pow ( 4 , len - i ) ; else { if ( j == 1 ) Console . Write ( "2" ) ; else if ( j == 2 ) Console . Write ( "3" ) ; else if ( j == 3 ) Console . Write ( "5" ) ; else if ( j == 4 ) Console . Write ( "7" ) ; break ; } } } Console . WriteLine ( ) ; } public static void Main ( ) { nthprimedigitsnumber ( 10 ) ; nthprimedigitsnumber ( 21 ) ; } }


"Finding n | C # program to find n - th number with prime digits 2 , 3 and 7 ; remainder for check element position ; if number is 1 st position in tree ; if number is 2 nd position in tree ; if number is 3 rd position in tree ; if number is 4 th position in tree ; Driver code"
Solution in C#:

using System ; class GFG { static string nthprimedigitsnumber ( int number ) { int rem ; string num = " " ; while ( number > 0 ) { rem = number % 4 ; switch ( rem ) { case 1 : num += '2' ; break ; case 2 : num += '3' ; break ; case 3 : num += '5' ; break ; case 0 : num += '7' ; break ; } if ( number % 4 == 0 ) number -- ; number = number / 4 ; } char [ ] st = num . ToCharArray ( ) ; Array . Reverse ( st ) ; return new string ( st ) ; } static void Main ( ) { int number = 21 ; Console . WriteLine ( nthprimedigitsnumber ( 10 ) ) ; Console . WriteLine ( nthprimedigitsnumber ( number ) ) ; } }


"Finding number of digits in n 'th Fibonacci number | C # program to find number of digits in nth Fibonacci number ; This function returns the number of digits in nth Fibonacci number after ceiling it Formula used ( n * log ( phi ) - ( log 5 ) / 2 ) ; using phi = 1.6180339887498948 ; Driver code"
Solution in C#:

using System ; class GFG { static double numberOfDigits ( double n ) { if ( n == 1 ) return 1 ; double d = ( n * Math . Log10 ( 1.6180339887498948 ) ) - ( ( Math . Log10 ( 5 ) ) / 2 ) ; return Math . Ceiling ( d ) ; } public static void Main ( ) { double i ; for ( i = 1 ; i <= 10 ; i ++ ) Console . WriteLine ( " Number ▁ of ▁ Digits ▁ in ▁ F ( " + i + " ) ▁ - ▁ " + numberOfDigits ( i ) ) ; } }


"Finding power of prime number p in n ! | C # implementation of finding power of p in n ! ; Method to calculate power of prime number p in n ! ; initializing answer ; initializing ; loop until temp <= n ; add number of numbers divisible by n ; each time multiply temp by p ; Driver Code"
Solution in C#:

using System ; public class GFG { static int PowerOFPINnfactorial ( int n , int p ) { int ans = 0 ; int temp = p ; while ( temp <= n ) { ans += n / temp ; temp = temp * p ; } return ans ; } public static void Main ( String [ ] args ) { Console . WriteLine ( PowerOFPINnfactorial ( 4 , 2 ) ) ; } }


"Finding powers of any number P in N ! | C # program to find the power of P in N ! ; Map to store all the prime factors of P ; Function to find the prime factors of N im Map ; Clear map ; Check for factors of 2 ; Find all the prime factors ; If i is a factors then increase the frequency of i ; Function to find the power of prime number P in N ! ; Loop until temp <= N ; Add the number of numbers divisible by N ; Each time multiply temp by P ; Returns ans ; Function that find the powers of any P in N ! ; Find all prime factors of number P ; To store the powers of all prime factors ; Traverse the map ; Prime factor and corres . powers ; Find power of prime factor primeFac ; Divide frequency by facPow ; Store the power of primeFac ^ facPow ; Return the minimum element in Power array ; Driver 's Code ; Function to find power of P in N !"
Solution in C#:

using System ; using System . Linq ; using System . Collections . Generic ; class GFG { static Dictionary < int , int > Map = new Dictionary < int , int > ( ) ; static void findPrimeFactors ( int N ) { int i ; Map . Clear ( ) ; while ( N % 2 == 0 ) { if ( Map . ContainsKey ( 2 ) ) Map [ 2 ] = Map [ 2 ] + 1 ; else Map . Add ( 2 , 1 ) ; N /= 2 ; } for ( i = 3 ; i <= Math . Sqrt ( N ) ; i += 2 ) { while ( N % i == 0 ) { if ( Map . ContainsKey ( i ) ) Map [ i ] = Map [ i ] + 1 ; else Map . Add ( i , 1 ) ; N /= i ; } } if ( N > 2 ) { if ( Map . ContainsKey ( N ) ) Map [ N ] = Map [ N ] + 1 ; else Map . Add ( N , 1 ) ; } } static int PowInFactN ( int N , int P ) { int ans = 0 ; int temp = P ; while ( temp <= N ) { ans += N / temp ; temp = temp * P ; } return ans ; } static int findPowers ( int N , int P ) { findPrimeFactors ( P ) ; List < int > Powers = new List < int > ( ) ; foreach ( KeyValuePair < int , int > it in Map ) { int primeFac = it . Key ; int facPow = it . Value ; int p = PowInFactN ( N , primeFac ) ; p /= facPow ; Powers . Add ( p ) ; } return Powers . Min ( ) ; } public static void Main ( String [ ] args ) { int N = 24 , P = 4 ; Console . Write ( findPowers ( N , P ) ) ; } }


"Finding shortest path between any two nodes using Floyd Warshall Algorithm | C # program to find the shortest path between any two nodes using Floyd Warshall Algorithm . ; Infinite value for array ; Initializing the distance and Next array ; No edge between node i and j ; Function construct the shortest path between u and v ; If there 's no path between  node u and v, simply return  an empty array ; Storing the path in a vector ; Standard Floyd Warshall Algorithm with little modification Now if we find that dis [ i , j ] > dis [ i , k ] + dis [ k , j ] then we modify next [ i , j ] = next [ i , k ] ; We cannot travel through edge that doesn 't exist ; Print the shortest path ; Driver code ; Function to initialise the distance and Next array ; Calling Floyd Warshall Algorithm , this will update the shortest distance as well as Next array ; Path from node 1 to 3 ; Path from node 0 to 2 ; Path from node 3 to 2"
Solution in C#:

 using System ; using System . Collections . Generic ; class GFG { static readonly int MAXN = 100 ; static int INF = ( int ) 1e7 ; static int [ , ] dis = new int [ MAXN , MAXN ] ; static int [ , ] Next = new int [ MAXN , MAXN ] ; static void initialise ( int V , int [ , ] graph ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { dis [ i , j ] = graph [ i , j ] ; if ( graph [ i , j ] == INF ) Next [ i , j ] = - 1 ; else Next [ i , j ] = j ; } } } static List < int > constructPath ( int u , int v ) { if ( Next [ u , v ] == - 1 ) return null ; List < int > path = new List < int > ( ) ; path . Add ( u ) ; while ( u != v ) { u = Next [ u , v ] ; path . Add ( u ) ; } return path ; } static void floydWarshall ( int V ) { for ( int k = 0 ; k < V ; k ++ ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { if ( dis [ i , k ] == INF dis [ k , j ] == INF ) continue ; if ( dis [ i , j ] > dis [ i , k ] + dis [ k , j ] ) { dis [ i , j ] = dis [ i , k ] + dis [ k , j ] ; Next [ i , j ] = Next [ i , k ] ; } } } } } static void printPath ( List < int > path ) { int n = path . Count ; for ( int i = 0 ; i < n - 1 ; i ++ ) Console . Write ( path [ i ] + " ▁ - > ▁ " ) ; Console . Write ( path [ n - 1 ] + "
 " ) ; } public static void Main ( String [ ] args ) { int V = 4 ; int [ , ] graph = { { 0 , 3 , INF , 7 } , { 8 , 0 , 2 , INF } , { 5 , INF , 0 , 1 } , { 2 , INF , INF , 0 } } ; initialise ( V , graph ) ; floydWarshall ( V ) ; List < int > path ; Console . Write ( " Shortest ▁ path ▁ from ▁ 1 ▁ to ▁ 3 : ▁ " ) ; path = constructPath ( 1 , 3 ) ; printPath ( path ) ; Console . Write ( " Shortest ▁ path ▁ from ▁ 0 ▁ to ▁ 2 : ▁ " ) ; path = constructPath ( 0 , 2 ) ; printPath ( path ) ; Console . Write ( " Shortest ▁ path ▁ from ▁ 3 ▁ to ▁ 2 : ▁ " ) ; path = constructPath ( 3 , 2 ) ; printPath ( path ) ; } }


"Finding sum of digits of a number until sum becomes single digit | C # program to find sum of digits of a number until sum becomes single digit . ; Loop to do sum while sum is not less than or equal to 9 ; Driver code"
Solution in C#:

using System ; class GFG { static int digSum ( int n ) { int sum = 0 ; while ( n > 0 sum > 9 ) { if ( n == 0 ) { n = sum ; sum = 0 ; } sum += n % 10 ; n /= 10 ; } return sum ; } public static void Main ( ) { int n = 1234 ; Console . Write ( digSum ( n ) ) ; } }


"Finding sum of digits of a number until sum becomes single digit | Driver Code"
Solution in C#:

using System ; class GFG { static int digSum ( int n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } public static void Main ( ) { int n = 9999 ; Console . Write ( digSum ( n ) ) ; } }


"Finding the Nth term in a sequence formed by removing digit K from natural numbers | C # implementation for the above approach ; Denotes the digit place ; Method to convert any number to binary equivalent ; denotes the current digits place ; If current digit is >= K increment its value by 1 ; Else add the digit as it is ; Move to the next digit ; Driver code"
Solution in C#:

using System ; class GFG { static long convertToBase9 ( long n ) { long ans = 0 ; long a = 1 ; while ( n > 0 ) { ans += ( a * ( n % 9 ) ) ; a *= 10 ; n /= 9 ; } return ans ; } static long getNthnumber ( long base9 , long K ) { long ans = 0 ; long a = 1 ; while ( base9 > 0 ) { int cur = ( int ) ( base9 % 10 ) ; if ( cur >= K ) { ans += a * ( cur + 1 ) ; } else { ans += a * cur ; } base9 /= 10 ; a *= 10 ; } return ans ; } public static void Main ( String [ ] args ) { long N = 10 , K = 1 ; long base9 = convertToBase9 ( N ) ; Console . Write ( getNthnumber ( base9 , K ) ) ; } }