codeparrot/xlcost-text-to-code huggingface dataset:
Count all possible values of K less than Y such that GCD ( X , Y ) = GCD ( X + K , Y ) | C # program for the above approach ; Function to find the gcd of a and b ; Function to find the number of Ks ; Find gcd ; Calculating value of totient function for n ; Driver Code ; Given X and Y
using System ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static int calculateK ( int x , int y ) { int g = gcd ( x , y ) ; int n = y / g ; int res = n ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { res -= ( res / i ) ; while ( n % i == 0 ) n /= i ; } } if ( n != 1 ) res -= ( res / n ) ; return res ; } public static void Main ( String [ ] args ) { int x = 3 , y = 15 ; Console . Write ( calculateK ( x , y ) + " STRNEWLINE " ) ; } }
Check if a Float value is equivalent to an Integer value | C # program to implement the above approach ; Function to check if N is equivalent to an integer ; Convert float value of N to integer ; If N is not equivalent to any integer ; Driver code
using System ; class GFG { static bool isint ( double N ) { int X = ( int ) N ; double temp2 = N - X ; if ( temp2 > 0 ) { return false ; } return true ; } public static void Main ( String [ ] args ) { double N = 1.5 ; if ( isint ( N ) ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } }
Find the nearest power of 2 for every array element | C # program to implement the above approach ; Function to find nearest power of two for every array element ; Traverse the array ; Calculate log of the current array element ; Find the nearest ; Driver Code
using System ; class GFG { static void nearestPowerOfTwo ( int [ ] arr , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int lg = ( int ) ( Math . Log ( arr [ i ] ) / Math . Log ( 2 ) ) ; int a = ( int ) ( Math . Pow ( 2 , lg ) ) ; int b = ( int ) ( Math . Pow ( 2 , lg + 1 ) ) ; if ( ( arr [ i ] - a ) < ( b - arr [ i ] ) ) Console . Write ( a + " ▁ " ) ; else Console . Write ( b + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 2 , 7 , 12 } ; int N = arr . Length ; nearestPowerOfTwo ( arr , N ) ; } }
Flip bits of the sum of count of set bits of two given numbers | C # program for the above approach ; Function to count number of set bits in integer ; Variable for counting set bits ; Function to invert bits of a number ; Calculate number of bits of N - 1 ; ; Function to invert the sum of set bits in A and B ; Stores sum of set bits ; Driver Code
using System ; class GFG { static int countSetBits ( int n ) { int count = 0 ; while ( n != 0 ) { n &= ( n - 1 ) ; count ++ ; } return count ; } static int invertBits ( int n ) { int x = ( int ) Math . Log ( n , 2 ) ; int m = 1 << x ; m = m | m - 1 ; n = n ^ m ; return n ; } static void invertSum ( int A , int B ) { int temp = countSetBits ( A ) + countSetBits ( B ) ; Console . WriteLine ( invertBits ( temp ) ) ; } static void Main ( ) { int A = 5 ; int B = 7 ; invertSum ( A , B ) ; } }
Sum of Bitwise XOR of each array element with all other array elements | C # program for the above approach ; Function to calculate for each array element , sum of its Bitwise XOR with all other array elements ; Declare an array of size 64 to store count of each bit ; Traversing the array ; Check if bit is present of not ; Increase the bit position ; Reduce the number to half ; Traverse the array ; Stores the bit position ; Stores the sum of Bitwise XOR ; Check if bit is present of not ; Reduce the number to its half ; Print the sum for A [ i ] ; Driver Code ; Given array ; Given N ; Function Call
using System ; class GFG { static void XOR_for_every_i ( int [ ] A , int N ) { int [ ] frequency_of_bits = new int [ 32 ] ; for ( int i = 0 ; i < N ; i ++ ) { int bit_position = 0 ; int M = A [ i ] ; while ( M != 0 ) { if ( ( M & 1 ) != 0 ) { frequency_of_bits [ bit_position ] += 1 ; } bit_position += 1 ; M >>= 1 ; } } for ( int i = 0 ; i < N ; i ++ ) { int M = A [ i ] ; int value_at_that_bit = 1 ; int XOR_sum = 0 ; for ( int bit_position = 0 ; bit_position < 32 ; bit_position ++ ) { if ( ( M & 1 ) != 0 ) { XOR_sum += ( N - frequency_of_bits [ bit_position ] ) * value_at_that_bit ; } else { XOR_sum += ( frequency_of_bits [ bit_position ] ) * value_at_that_bit ; } M >>= 1 ; value_at_that_bit <<= 1 ; } Console . Write ( XOR_sum + " ▁ " ) ; } return ; } public static void Main ( ) { int [ ] A = { 1 , 2 , 3 } ; int N = A . Length ; XOR_for_every_i ( A , N ) ; } }
Minimize the maximum difference of any pair by doubling odd elements and reducing even elements by half | C # program for the above approach ; Function to minimize the maximum difference between any pair of elements of the array by the given operations ; Traverse the array ; If current element is even ; Insert it into even ; Otherwise ; Make it even by multiplying by 2 and insert it into set ; Calculate difference between first and the last element of the set ; Iterate until difference is minimized ; Erase the current element ; Reduce current element by half and insert it into the Set ; Update difference ; Return the resultant difference ; Driver code
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { static int minimumMaxDiff ( int [ ] nums ) { HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < nums . Length ; i ++ ) { if ( nums [ i ] % 2 == 0 ) s . Add ( nums [ i ] ) ; else s . Add ( nums [ i ] * 2 ) ; } int res = s . Last ( ) - s . First ( ) ; while ( s . Last ( ) % 2 == 0 ) { int x = s . Last ( ) ; s . Remove ( x ) ; s . Add ( x / 2 ) ; res = Math . Min ( res , s . Last ( ) - s . First ( ) ) ; } return res ; } static public void Main ( ) { int [ ] arr = new int [ ] { 1 , 2 , 5 , 9 } ; Console . WriteLine ( minimumMaxDiff ( arr ) ) ; } }
XOR of all even numbers from a given range | C # Implementation of the above approach ; Function to calculate XOR of numbers in the range [ 1 , n ] ; If n is divisible by 4 ; If n mod 4 is equal to 1 ; If n mod 4 is equal to 2 ; Function to find XOR of even numbers in the range [ l , r ] ; Stores XOR of even numbers in the range [ 1 , l - 1 ] ; Stores XOR of even numbers in the range [ 1 , r ] ; Update xor_r ; Update xor_l ; Driver code
using System ; class GFG { static int bitwiseXorRange ( int n ) { if ( n % 4 == 0 ) return n ; if ( n % 4 == 1 ) return 1 ; if ( n % 4 == 2 ) return n + 1 ; return 0 ; } static int evenXorRange ( int l , int r ) { int xor_l ; int xor_r ; xor_r = 2 * bitwiseXorRange ( r / 2 ) ; xor_l = 2 * bitwiseXorRange ( ( l - 1 ) / 2 ) ; return xor_l ^ xor_r ; } static void Main ( ) { int l = 10 ; int r = 20 ; Console . Write ( evenXorRange ( l , r ) ) ; } }
Program to calculate Variance of first N Natural Numbers | C # program to implement the above approach ; Function to calculate Variance of first N natural numbers ; Driver Code
using System ; class GFG { static double find_Variance ( int n ) { long numerator = n * n - 1 ; double ans = ( numerator * 1.0 ) / 12 ; return ans ; } public static void Main ( string [ ] args ) { int N = 5 ; Console . WriteLine ( find_Variance ( N ) ) ; } }
Count digits present in each element of a given Matrix | C # program to implement the above approach ; Function to count the number of digits in each element of the given matrix ; Traverse each row of arr [ ] [ ] ; Traverse each column of arr [ ] [ ] ; Store the current matrix element ; Count the number of digits ; Print the result ; Driver Code ; Given matrix
using System ; class GFG { static int M = 3 ; static int N = 3 ; static void countDigit ( int [ , ] arr ) { for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { int X = arr [ i , j ] ; int d = ( int ) ( Math . Floor ( Math . Log10 ( X ) * 1.0 ) + 1 ) ; Console . Write ( d + " ▁ " ) ; } Console . WriteLine ( ) ; } } public static void Main ( ) { int [ , ] arr = { { 27 , 173 , 5 } , { 21 , 6 , 624 } , { 5 , 321 , 49 } } ; countDigit ( arr ) ; } }
Difference between sum of odd and even frequent elements in an Array | C # program to find absolute difference between the sum of all odd frequenct and even frequent elements in an array ; Function to find the sum of all even and odd frequent elements in an array ; Stores the frequency of array elements ; Traverse the array ; Update frequency of current element ; Stores sum of odd and even frequent elements ; Traverse the map ; If frequency is odd ; Add sum of all occurrences of current element to sum_odd ; If frequency is even ; Add sum of all occurrences of current element to sum_even ; Calculate difference between their sum ; Return diff ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int findSum ( int [ ] arr , int N ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] ++ ; } else { mp [ arr [ i ] ] = 1 ; } } int sum_odd = 0 , sum_even = 0 ; foreach ( KeyValuePair < int , int > itr in mp ) { if ( itr . Value % 2 != 0 ) sum_odd += ( itr . Key ) * ( itr . Value ) ; if ( itr . Value % 2 == 0 ) sum_even += ( itr . Key ) * ( itr . Value ) ; } int diff = sum_even - sum_odd ; return diff ; } static void Main ( ) { int [ ] arr = { 1 , 5 , 5 , 2 , 4 , 3 , 3 } ; int N = arr . Length ; Console . Write ( findSum ( arr , N ) ) ; } }
Count N | C # program to implement the above approach ; Function to find the number of arrays following the given condition ; Initialize answer ; Calculate nPm ; Print ans ; Driver Code ; Given N and M ; Function Call
using System ; class GFG { static void noOfArraysPossible ( int N , int M ) { int ans = 1 ; for ( int i = 0 ; i < N ; ++ i ) { ans = ans * ( M - i ) ; } Console . Write ( ans ) ; } public static void Main ( ) { int N = 2 , M = 3 ; noOfArraysPossible ( N , M ) ; } }
Permutations of an array having sum of Bitwise AND of adjacent elements at least K | C # program for the above approach ; Function to print all permutations of [ ] arr such that the sum of Bitwise AND of all adjacent element is at least K ; To check if any permutation exists or not ; Sort the given array ; Find all possible permutations ; Stores the sum of bitwise AND of adjacent elements of the current permutation ; Traverse the current permutation of [ ] arr ; Update the sum ; If the sum is at least K , then print the current permutation ; Set the flag variable ; Print the current permutation ; If flag is unset , then print - 1 ; Driver Code ; Function Call
using System ; class GFG { static void printPermutation ( int [ ] arr , int n , int k ) { bool flag = false ; Array . Sort ( arr ) ; do { int sum = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { sum += arr [ i ] & arr [ i + 1 ] ; } if ( sum >= k ) { flag = true ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } Console . Write ( " STRNEWLINE " ) ; } } while ( next_permutation ( arr ) ) ; if ( flag == false ) { Console . Write ( " - 1" ) ; } } static bool next_permutation ( int [ ] p ) { for ( int a = p . Length - 2 ; a >= 0 ; -- a ) if ( p [ a ] < p [ a + 1 ] ) for ( int b = p . Length - 1 ; ; -- b ) if ( p [ b ] > p [ a ] ) { int t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; for ( ++ a , b = p . Length - 1 ; a < b ; ++ a , -- b ) { t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; } return true ; } return false ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int K = 8 ; int N = arr . Length ; printPermutation ( arr , N , K ) ; } }
Sum of the first N terms of XOR Fibonacci series | C # program for the above approach ; Function to calculate the sum of the first N terms of XOR Fibonacci Series ; Base Case ; Stores the sum of the first N terms ; Iterate from [ 0 , n - 3 ] ; Store XOR of last 2 elements ; Update sum ; Update the first element ; Update the second element ; Print the final sum ; Driver Code ; Function Call
using System ; class GFG { static void findSum ( int a , int b , int n ) { if ( n == 1 ) { Console . WriteLine ( a ) ; return ; } int s = a + b ; for ( int i = 0 ; i < n - 2 ; i ++ ) { int x = a ^ b ; s += x ; a = b ; b = x ; } Console . WriteLine ( s ) ; } public static void Main ( ) { int a = 2 , b = 5 , N = 8 ; findSum ( a , b , N ) ; } }
Sum of the first N terms of XOR Fibonacci series | C # program for the above approach ; Function to calculate sum of the first N terms of XOR Fibonacci Series ; Store the sum of first n terms ; Store XOR of a and b ; Case 1 : If n is divisible by 3 ; Case 2 : If n % 3 leaves remainder 1 ; Case 3 : If n % 3 leaves remainder 2 on division by 3 ; Print the final sum ; Driver Code ; Function Call
using System ; class GFG { static void findSum ( int a , int b , int n ) { int sum = 0 ; int x = a ^ b ; if ( n % 3 == 0 ) { sum = ( n / 3 ) * ( a + b + x ) ; } else if ( n % 3 == 1 ) { sum = ( n / 3 ) * ( a + b + x ) + a ; } else { sum = ( n / 3 ) * ( a + b + x ) + a + b ; } Console . Write ( sum ) ; } public static void Main ( String [ ] args ) { int a = 2 , b = 5 , N = 8 ; findSum ( a , b , N ) ; } }
Length of the longest subarray whose Bitwise XOR is K | C # program to implement the above approach ; Function to find the length of the longest subarray whose bitwise XOR is equal to K ; Stores prefix XOR of the array ; Stores length of longest subarray having bitwise XOR equal to K ; Stores index of prefix XOR of the array ; Insert 0 into the map ; Traverse the array ; Update prefixXOR ; If ( prefixXOR ^ K ) present in the map ; Update maxLen ; If prefixXOR not present in the Map ; Insert prefixXOR into the map ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int longestLenXORK ( int [ ] arr , int N , int K ) { int prefixXOR = 0 ; int maxLen = 0 ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; mp . Add ( 0 , - 1 ) ; for ( int i = 0 ; i < N ; i ++ ) { prefixXOR ^= arr [ i ] ; if ( mp . ContainsKey ( prefixXOR ^ K ) ) { maxLen = Math . Max ( maxLen , ( i - mp [ prefixXOR ^ K ] ) ) ; } if ( ! mp . ContainsKey ( prefixXOR ) ) { mp . Add ( prefixXOR , i ) ; } } return maxLen ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 4 , 7 , 2 } ; int N = arr . Length ; int K = 1 ; Console . Write ( longestLenXORK ( arr , N , K ) ) ; } }
Two Dimensional Difference Array | C # program to implement the above approach ; Function to initialize the difference array ; Function to add k to the specified submatrix ( r1 , c1 ) to ( r2 , c2 ) ; Function to print the modified array ; Function to perform the given queries ; Difference array ; Function to initialize the difference array ; Count of queries ; Perform Queries ; Driver Code ; Given Matrix ; Given Queries
using System ; using System . Collections . Generic ; class GFG { static int N = 3 ; static int M = 3 ; static void intializeDiff ( int [ , ] D , int [ , ] A ) { for ( int i = 0 ; i < N ; i ++ ) { D [ i , 0 ] = A [ i , 0 ] ; D [ i , M ] = 0 ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 1 ; j < M ; j ++ ) D [ i , j ] = A [ i , j ] - A [ i , j - 1 ] ; } } static void update ( int [ , ] D , int k , int r1 , int c1 , int r2 , int c2 ) { for ( int i = r1 ; i <= r2 ; i ++ ) { D [ i , c1 ] += k ; D [ i , c2 + 1 ] -= k ; } } static void printArray ( int [ , ] A , int [ , ] D ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( j == 0 ) A [ i , j ] = D [ i , j ] ; else A [ i , j ] = D [ i , j ] + A [ i , j - 1 ] ; Console . Write ( A [ i , j ] + " ▁ " ) ; } Console . WriteLine ( ) ; } } static void performQueries ( int [ , ] A , List < List < int > > Queries ) { int [ , ] D = new int [ N , M + 1 ] ; intializeDiff ( D , A ) ; int Q = Queries . Count ; for ( int i = 0 ; i < Q ; i ++ ) { update ( D , Queries [ i ] [ 0 ] , Queries [ i ] [ 1 ] , Queries [ i ] [ 2 ] , Queries [ i ] [ 3 ] , Queries [ i ] [ 4 ] ) ; } printArray ( A , D ) ; } static void Main ( ) { int [ , ] A = { { 1 , 2 , 3 } , { 1 , 1 , 0 } , { 4 , - 2 , 2 } } ; List < List < int > > Queries = new List < List < int > > ( ) ; Queries . Add ( new List < int > { 2 , 0 , 0 , 1 , 1 } ) ; Queries . Add ( new List < int > { - 1 , 1 , 0 , 2 , 2 } ) ; performQueries ( A , Queries ) ; } }
Minimum value to be added to maximize Bitwise XOR of the given array | C # program for the above approach ; Function to find complement of an integer ; Count the number of bits of maxElement ; Return 1 's complement ; Function to find the value required to be added to maximize XOR of the given array ; Stores the required value to be added to the array ; Stores the maximum array element ; Traverse the array ; Update XOR of the array ; Find maximum element in array ; Calculate 1 s ' complement ; Return the answer ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int onesComplement ( int n , int maxElement ) { int bits = ( int ) Math . Floor ( ( Math . Log ( maxElement ) / Math . Log ( 2 ) ) ) + 1 ; return ( ( 1 << bits ) - 1 ) ^ n ; } static int findNumber ( int [ ] arr , int n ) { int res = 0 ; int maxElement = 0 ; for ( int i = 0 ; i < n ; i ++ ) { res = res ^ arr [ i ] ; if ( maxElement < arr [ i ] ) maxElement = arr [ i ] ; } res = onesComplement ( res , maxElement ) ; return ( res ) ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int N = arr . Length ; Console . Write ( findNumber ( arr , N ) ) ; } }
Count ways to select K array elements lying in a given range | C # program to implement the above approach ; Function to calculate factorial of all the numbers up to N ; Factorial of 0 is 1 ; Calculate factorial of all the numbers upto N ; Calculate factorial of i ; Function to find the count of ways to select at least K elements whose values in range [ L , R ] ; Stores count of ways to select at least K elements whose values in range [ L , R ] ; Stores count of numbers having value lies in the range [ L , R ] ; Traverse the array ; Checks if the array elements lie in the given range ; Update cntNum ; Stores factorial of numbers upto N ; Calculate total ways to select at least K elements whose values lies in [ L , R ] ; Update cntWays ; Driver Code
using System ; class GFG { static int [ ] calculateFactorial ( int N ) { int [ ] fact = new int [ ( N + 1 ) ] ; fact [ 0 ] = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { fact [ i ] = fact [ i - 1 ] * i ; } return fact ; } static int cntWaysSelection ( int [ ] arr , int N , int K , int L , int R ) { int cntWays = 0 ; int cntNum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= L && arr [ i ] <= R ) { cntNum ++ ; } } int [ ] fact = calculateFactorial ( cntNum ) ; for ( int i = K ; i <= cntNum ; i ++ ) { cntWays += fact [ cntNum ] / ( fact [ i ] * fact [ cntNum - i ] ) ; } return cntWays ; } public static void Main ( ) { int [ ] arr = { 12 , 4 , 6 , 13 , 5 , 10 } ; int N = arr . Length ; int K = 3 ; int L = 4 ; int R = 10 ; Console . WriteLine ( cntWaysSelection ( arr , N , K , L , R ) ) ; } }
Bitwise AND of all unordered pairs from a given array | C # program to implement the above approach ; Function to calculate bitwise AND of all pairs from the given array ; Stores bitwise AND of all possible pairs ; Generate all possible pairs ; Calculate bitwise AND of each pair ; Driver Code
using System ; class GFG { static int TotalAndPair ( int [ ] arr , int N ) { int totalAND = ( 1 << 30 ) - 1 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { totalAND &= arr [ i ] & arr [ j ] ; } } return totalAND ; } public static void Main ( ) { int [ ] arr = { 4 , 5 , 12 , 15 } ; int N = arr . Length ; Console . Write ( TotalAndPair ( arr , N ) ) ; } }
Modify N by adding its smallest positive divisor exactly K times | C # program to implement the above approach ; Function to find the smallest divisor of N greater than 1 ; If i is a divisor of N ; If N is a prime number ; Function to find the value of N by performing the operations K times ; Iterate over the range [ 1 , K ] ; Update N ; Driver Code
using System ; public class GFG { static int smallestDivisorGr1 ( int N ) { for ( int i = 2 ; i <= Math . Sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { return i ; } } return N ; } static int findValOfNWithOperat ( int N , int K ) { for ( int i = 1 ; i <= K ; i ++ ) { N += smallestDivisorGr1 ( N ) ; } return N ; } public static void Main ( String [ ] args ) { int N = 6 , K = 4 ; Console . Write ( findValOfNWithOperat ( N , K ) ) ; } }
Sum of all possible triplet products from given ranges | C # program to implement the above approach ; Function to find the sum of all possible triplet products ( i * j * k ) ; Stores sum required sum ; Iterate over all possible values of i ; Iterate over all possible values of j ; Iterate over all possible values of k ; Stores the product of ( i * j * k ) ; Update sum ; Driver Code
using System ; class GFG { static int M = 1000000007 ; static int findTripleSum ( int A , int B , int C ) { int sum = 0 ; for ( int i = 1 ; i <= A ; i ++ ) { for ( int j = 1 ; j <= B ; j ++ ) { for ( int k = 1 ; k <= C ; k ++ ) { int prod = ( ( ( i % M ) * ( j % M ) ) % M * ( k % M ) ) % M ; sum = ( sum + prod ) % M ; } } } return sum ; } public static void Main ( ) { int A = 10 ; int B = 100 ; int C = 1000 ; Console . WriteLine ( findTripleSum ( A , B , C ) ) ; } }
Sum of all possible triplet products from given ranges | C # implementation to implement the above approach ; Function to find the value of power ( X , N ) % M ; Stores the value of ( X ^ N ) % M ; Calculate the value of power ( x , N ) % M ; If N is odd ; Update res ; Update x ; Update N ; Function to find modulo multiplicative inverse of X under modulo M ; Function to find the sum of all possible triplet products ( i * j * k ) ; Stores modulo multiplicative inverse of 8 ; Stores the sum of all possible values of ( i * j * k ) ; Update res ; Driver Code
using System ; class GFG { static readonly int M = 1000000007 ; static long power ( long x , long N ) { long res = 1 ; while ( N > 0 ) { if ( N % 2 == 1 ) { res = ( res * x ) % M ; } x = ( x * x ) % M ; N = N >> 1 ; } return res ; } static long modinv ( long X ) { return power ( X , M - 2 ) ; } static long findTripleSum ( long A , long B , long C ) { long MMI = modinv ( 8 ) ; long res = 0 ; res = ( ( ( ( A % M * ( A + 1 ) % M ) % M * ( B % M * ( B + 1 ) % M ) % M ) % M * ( C % M * ( C + 1 ) % M ) % M ) % M * MMI ) % M ; return res ; } public static void Main ( String [ ] args ) { long A = 10 ; long B = 100 ; long C = 1000 ; Console . Write ( findTripleSum ( A , B , C ) ) ; } }
Maximize minimum of array generated by maximums of same indexed elements of two rows of a given Matrix | C # program for the above approach ; Function to find the maximum of minimum of array constructed from any two rows of the given matrix ; Initialize global max as INT_MIN ; Iterate through the rows ; Iterate through remaining rows ; Initialize row_min as INT_MAX ; Iterate through the column values of two rows ; Find max of two elements ; Update the row_min ; Update the global_max ; Print the global max ; Driver Code ; Given matrix mat [ ] [ ] ; Given number of rows and columns ; Function Call
using System ; class GFG { static int getMaximum ( int N , int M , int [ , ] mat ) { int global_max = int . MinValue ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int row_min = int . MaxValue ; for ( int k = 0 ; k < M ; k ++ ) { int m = Math . Max ( mat [ i , k ] , mat [ j , k ] ) ; row_min = Math . Min ( row_min , m ) ; } global_max = Math . Max ( global_max , row_min ) ; } } return global_max ; } public static void Main ( ) { int [ , ] mat = { { 5 , 0 , 3 , 1 , 2 } , { 1 , 8 , 9 , 1 , 3 } , { 1 , 2 , 3 , 4 , 5 } , { 9 , 1 , 0 , 3 , 7 } , { 2 , 3 , 0 , 6 , 3 } , { 6 , 4 , 1 , 7 , 0 } } ; int N = 6 , M = 5 ; Console . WriteLine ( getMaximum ( N , M , mat ) ) ; } }