codeparrot/xlcost-text-to-code huggingface dataset:
Maximum points of intersection n lines | C # program to find maximum intersecting points ; nC2 = ( n ) * ( n - 1 ) / 2 ; ; Driver code ; n is number of line
using System ; class GFG { public static long countMaxIntersect ( long n ) { return ( n ) * ( n - 1 ) / 2 ; } public static void Main ( ) { long n = 8 ; Console . WriteLine ( countMaxIntersect ( n ) ) ; } }
Program to find volume and surface area of pentagonal prism | C # program to find surface area and volume of the Pentagonal Prism ; function for surface area ; function for VOlume ; Driver Code
using System ; class GFG { static float surfaceArea ( float a , float b , float h ) { return 5 * a * b + 5 * b * h ; } static float volume ( float b , float h ) { return ( 5 * b * h ) / 2 ; } public static void Main ( ) { float a = 5 ; float b = 3 ; float h = 7 ; Console . WriteLine ( " surface ▁ area ▁ = ▁ " + surfaceArea ( a , b , h ) + " , ▁ " ) ; Console . WriteLine ( " volume ▁ = ▁ " + volume ( b , h ) ) ; } }
Check if a point is inside , outside or on the parabola | C # Program to check if the point lies within the parabola or not ; Function to check the point ; checking the equation of parabola with the given point ; Driver code
using System ; class GFG { public static int checkpoint ( int h , int k , int x , int y , int a ) { int p = ( int ) Math . Pow ( ( y - k ) , 2 ) - 4 * a * ( x - h ) ; return p ; } public static void Main ( string [ ] arr ) { int h = 0 , k = 0 , x = 2 , y = 1 , a = 4 ; if ( checkpoint ( h , k , x , y , a ) > 0 ) { Console . WriteLine ( " Outside " ) ; } else if ( checkpoint ( h , k , x , y , a ) == 0 ) { Console . WriteLine ( " On ▁ the ▁ parabola " ) ; } else { Console . WriteLine ( " Inside " ) ; } } }
Check if a point is inside , outside or on the ellipse | C # Program to check if the point lies within the ellipse or not ; Function to check the point ; checking the equation of ellipse with the given point ; Driver code
using System ; class GFG { static int checkpoint ( int h , int k , int x , int y , int a , int b ) { int p = ( ( int ) Math . Pow ( ( x - h ) , 2 ) / ( int ) Math . Pow ( a , 2 ) ) + ( ( int ) Math . Pow ( ( y - k ) , 2 ) / ( int ) Math . Pow ( b , 2 ) ) ; return p ; } public static void Main ( ) { int h = 0 , k = 0 , x = 2 , y = 1 , a = 4 , b = 5 ; if ( checkpoint ( h , k , x , y , a , b ) > 1 ) Console . WriteLine ( " Outside " ) ; else if ( checkpoint ( h , k , x , y , a , b ) == 1 ) Console . WriteLine ( " On ▁ the ▁ ellipse " ) ; else Console . WriteLine ( " Inside " ) ; } }
Area of circle inscribed within rhombus | C # Program to find the area of the circle which can be inscribed within the rhombus ; Function to find the area of the inscribed circle ; the diagonals cannot be negative ; area of the circle ; Driver code
using System ; public class GFG { public static float circlearea ( double a , double b ) { if ( a < 0 b < 0 ) return - 1 ; float A = ( float ) ( ( 3.14 * Math . Pow ( a , 2 ) * Math . Pow ( b , 2 ) ) / ( 4 * ( Math . Pow ( a , 2 ) + Math . Pow ( b , 2 ) ) ) ) ; return A ; } public static void Main ( ) { float a = 8 , b = 10 ; Console . WriteLine ( circlearea ( a , b ) ) ; } }
The biggest possible circle that can be inscribed in a rectangle | C # Program to find the biggest circle which can be inscribed within the rectangle ; Function to find the area of the biggest circle ; the length and breadth cannot be negative ; area of the circle ; Driver code
using System ; class GFG { static float circlearea ( float l , float b ) { if ( l < 0 b < 0 ) return - 1 ; if ( l < b ) return ( float ) ( 3.14 * Math . Pow ( l / 2 , 2 ) ) ; else return ( float ) ( 3.14 * Math . Pow ( b / 2 , 2 ) ) ; } public static void Main ( ) { float l = 4 , b = 8 ; Console . Write ( circlearea ( l , b ) ) ; } }
Centered cube number | C # Program to find nth Centered cube number ; Function to find Centered cube number ; Formula to calculate nth Centered cube number & return it into main function . ; Driver code
using System ; class GFG { static int centered_cube ( int n ) { return ( 2 * n + 1 ) * ( n * n + n + 1 ) ; } static public void Main ( ) { int n = 3 ; Console . Write ( n + " th ▁ Centered " + " ▁ cube ▁ number : ▁ " ) ; Console . WriteLine ( centered_cube ( n ) ) ; n = 10 ; Console . Write ( n + " th ▁ Centered " + " ▁ cube ▁ number : ▁ " ) ; Console . WriteLine ( centered_cube ( n ) ) ; } }
Find the center of the circle using endpoints of diameter | C # program to find the center of the circle ; function to find the center of the circle ; Driver Program to test above function
using System ; class GFG { static void center ( int x1 , int x2 , int y1 , int y2 ) { Console . WriteLine ( ( float ) ( x1 + x2 ) / 2 + " , ▁ " + ( float ) ( y1 + y2 ) / 2 ) ; } public static void Main ( ) { int x1 = - 9 , y1 = 3 , x2 = 5 , y2 = - 7 ; center ( x1 , x2 , y1 , y2 ) ; } }
Program to calculate volume of Octahedron | C # Program to calculate volume of Octahedron ; Driver Function ; utility Function
using System ; class GFG { public static void Main ( ) { double side = 3 ; Console . Write ( " Volume ▁ of ▁ octahedron ▁ = ▁ " ) ; Console . WriteLine ( vol_of_octahedron ( side ) ) ; } static double vol_of_octahedron ( double side ) { return ( ( side * side * side ) * ( Math . Sqrt ( 2 ) / 3 ) ) ; } }
Program to calculate volume of Ellipsoid | C # program to find the volume of Ellipsoid . ; Function to find the volume ; Driver Code
using System ; class GfG { public static float volumeOfEllipsoid ( float r1 , float r2 , float r3 ) { float pi = ( float ) 3.14 ; return ( float ) 1.33 * pi * r1 * r2 * r3 ; } public static void Main ( ) { float r1 = ( float ) 2.3 , r2 = ( float ) 3.4 , r3 = ( float ) 5.7 ; Console . WriteLine ( " volume ▁ of ▁ ellipsoid ▁ is ▁ : ▁ " + volumeOfEllipsoid ( r1 , r2 , r3 ) ) ; } }
Program to calculate Area Of Octagon | C # Program to find area of Octagon . ; utility function ; Driver code
using System ; class GFG { static double areaOctagon ( double side ) { return ( float ) ( 2 * ( 1 + Math . Sqrt ( 2 ) ) * side * side ) ; } public static void Main ( ) { double side = 4 ; Console . WriteLine ( " Area ▁ of ▁ Regular ▁ Octagon ▁ = ▁ " + areaOctagon ( side ) ) ; } }
Program for Volume and Surface Area of Cube | C # program to find area and total surface area of cube ; utility function ; Driver code
using System ; class GFG { static double areaCube ( double a ) { return ( a * a * a ) ; } static double surfaceCube ( double a ) { return ( 6 * a * a ) ; } public static void Main ( ) { double a = 5 ; Console . WriteLine ( " Area ▁ = ▁ " + areaCube ( a ) ) ; Console . WriteLine ( " Total ▁ surface ▁ area ▁ = ▁ " + surfaceCube ( a ) ) ; } }
Find mirror image of a point in 2 | C # code to find mirror image ; function which finds coordinates of mirror image . This function return a pair of double ; Driver code
using System ; class GFG { class pair { public double first , second ; public pair ( double first , double second ) { this . first = first ; this . second = second ; } } static pair mirrorImage ( double a , double b , double c , double x1 , double y1 ) { double temp = - 2 * ( a * x1 + b * y1 + c ) / ( a * a + b * b ) ; double x = temp * a + x1 ; double y = temp * b + y1 ; return new pair ( x , y ) ; } public static void Main ( String [ ] args ) { double a = - 1.0 ; double b = 1.0 ; double c = 0.0 ; double x1 = 1.0 ; double y1 = 0.0 ; pair image = mirrorImage ( a , b , c , x1 , y1 ) ; Console . Write ( " Image ▁ of ▁ point ▁ ( " + x1 + " , ▁ " + y1 + " ) ▁ " ) ; Console . Write ( " by ▁ mirror ▁ ( " + a + " ) x ▁ + ▁ ( " + b + " ) y ▁ + ▁ ( " + c + " ) ▁ = ▁ 0 , ▁ is ▁ : " ) ; Console . WriteLine ( " ( " + image . first + " , ▁ " + image . second + " ) " ) ; } }
Program for Point of Intersection of Two Lines | C # Implementation . To find the point of intersection of two lines ; Class used to used to store the X and Y coordinates of a point respectively ; Method used to display X and Y coordinates of a point ; Line AB represented as a1x + b1y = c1 ; Line CD represented as a2x + b2y = c2 ; The lines are parallel . This is simplified by returning a pair of FLT_MAX ; Driver method ; NOTE : Further check can be applied in case of line segments . Here , we have considered AB and CD as lines
using System ; public class Point { public double x , y ; public Point ( double x , double y ) { this . x = x ; this . y = y ; } public static void displayPoint ( Point p ) { Console . WriteLine ( " ( " + p . x + " , ▁ " + p . y + " ) " ) ; } } public class Test { public static Point lineLineIntersection ( Point A , Point B , Point C , Point D ) { double a1 = B . y - A . y ; double b1 = A . x - B . x ; double c1 = a1 * ( A . x ) + b1 * ( A . y ) ; double a2 = D . y - C . y ; double b2 = C . x - D . x ; double c2 = a2 * ( C . x ) + b2 * ( C . y ) ; double determinant = a1 * b2 - a2 * b1 ; if ( determinant == 0 ) { return new Point ( double . MaxValue , double . MaxValue ) ; } else { double x = ( b2 * c1 - b1 * c2 ) / determinant ; double y = ( a1 * c2 - a2 * c1 ) / determinant ; return new Point ( x , y ) ; } } public static void Main ( string [ ] args ) { Point A = new Point ( 1 , 1 ) ; Point B = new Point ( 4 , 4 ) ; Point C = new Point ( 1 , 8 ) ; Point D = new Point ( 2 , 4 ) ; Point intersection = lineLineIntersection ( A , B , C , D ) ; if ( intersection . x == double . MaxValue && intersection . y == double . MaxValue ) { Console . WriteLine ( " The ▁ given ▁ lines ▁ AB ▁ and ▁ CD ▁ are ▁ parallel . " ) ; } else { Console . Write ( " The ▁ intersection ▁ of ▁ the ▁ given ▁ lines ▁ AB ▁ " + " and ▁ CD ▁ is : ▁ " ) ; Point . displayPoint ( intersection ) ; } } }
Minimum revolutions to move center of a circle to a target | C # program to find minimum number of revolutions to reach a target center ; Minimum revolutions to move center from ( x1 , y1 ) to ( x2 , y2 ) ; Driver Program to test above function
using System ; class GFG { static double minRevolutions ( double r , int x1 , int y1 , int x2 , int y2 ) { double d = Math . Sqrt ( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) ) ; return Math . Ceiling ( d / ( 2 * r ) ) ; } public static void Main ( ) { int r = 2 , x1 = 0 , y1 = 0 ; int x2 = 0 , y2 = 4 ; Console . Write ( ( int ) minRevolutions ( r , x1 , y1 , x2 , y2 ) ) ; } }
Find all sides of a right angled triangle from given hypotenuse and area | Set 1 | C # program to get right angle triangle , given hypotenuse and area of triangle ; limit for float comparison ; Utility method to get area of right angle triangle , given base and hypotenuse ; Prints base and height of triangle using hypotenuse and area information ; maximum area will be obtained when base and height are equal ( = sqrt ( h * h / 2 ) ) ; if given area itself is larger than maxArea then no solution is possible ; binary search for base ; get height by pythagorean rule ; Driver code to test above methods
using System ; public class GFG { static double eps = ( double ) 1e-6 ; static double getArea ( double base1 , double hypotenuse ) { double height = Math . Sqrt ( hypotenuse * hypotenuse - base1 * base1 ) ; return 0.5 * base1 * height ; } static void printRightAngleTriangle ( int hypotenuse , int area ) { int hsquare = hypotenuse * hypotenuse ; double sideForMaxArea = Math . Sqrt ( hsquare / 2.0 ) ; double maxArea = getArea ( sideForMaxArea , hypotenuse ) ; if ( area > maxArea ) { Console . Write ( " Not ▁ possible " ) ; return ; } double low = 0.0 ; double high = sideForMaxArea ; double base1 = 0 ; while ( Math . Abs ( high - low ) > eps ) { base1 = ( low + high ) / 2.0 ; if ( getArea ( base1 , hypotenuse ) >= area ) { high = base1 ; } else { low = base1 ; } } double height = Math . Sqrt ( hsquare - base1 * base1 ) ; Console . WriteLine ( Math . Round ( base1 ) + " ▁ " + Math . Round ( height ) ) ; } static public void Main ( ) { int hypotenuse = 5 ; int area = 6 ; printRightAngleTriangle ( hypotenuse , area ) ; } }
Circle and Lattice Points | C # program to find countLattice points on a circle ; Function to count Lattice points on a circle ; Initialize result as 4 for ( r , 0 ) , ( - r . 0 ) , ( 0 , r ) and ( 0 , - r ) ; Check every value that can be potential x ; Find a potential y ; checking whether square root is an integer or not . Count increments by 4 for four different quadrant values ; Driver code
using System ; class GFG { static int countLattice ( int r ) { if ( r <= 0 ) return 0 ; int result = 4 ; for ( int x = 1 ; x < r ; x ++ ) { int ySquare = r * r - x * x ; int y = ( int ) Math . Sqrt ( ySquare ) ; if ( y * y == ySquare ) result += 4 ; } return result ; } public static void Main ( ) { int r = 5 ; Console . Write ( countLattice ( r ) ) ; } }
Count of subarrays of size K with average at least M | C # program for the above approach ; Driver Code ; Function to count the subarrays of size K having average at least M ; Stores the resultant count of subarray ; Stores the sum of subarrays of size K ; Add the values of first K elements to the sum ; Increment the count if the current subarray is valid ; Traverse the given array ; Find the updated sum ; Check if current subarray is valid or not ; Return the count of subarrays
using System ; public class GFG { public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 6 , 3 , 2 , 1 , 3 , 9 } ; int K = 2 , M = 4 ; Console . WriteLine ( countSubArrays ( arr , K , M ) ) ; } public static int countSubArrays ( int [ ] arr , int K , int M ) { int count = 0 ; int sum = 0 ; for ( int i = 0 ; i < K ; i ++ ) { sum += arr [ i ] ; } if ( sum >= K * M ) count ++ ; for ( int i = K ; i < arr . Length ; i ++ ) { sum += ( arr [ i ] - arr [ i - K ] ) ; if ( sum >= K * M ) count ++ ; } return count ; } }
Count of Ks in the Array for a given range of indices after array updates for Q queries | C # program for the above approach ; Function to perform all the queries ; Stores the count of 0 s ; Count the number of 0 s for query of type 1 ; Update the array element for query of type 2 ; Driver Code
using System ; public class GFG { static void performQueries ( int n , int q , int k , int [ ] arr , int [ , ] query ) { for ( int i = 1 ; i <= q ; i ++ ) { int count = 0 ; if ( query [ i - 1 , 0 ] == 1 ) { for ( int j = query [ i - 1 , 1 ] ; j <= query [ i - 1 , 2 ] ; j ++ ) { if ( arr [ j ] == k ) count ++ ; } Console . WriteLine ( count ) ; } else { arr [ query [ i - 1 , 1 ] ] = query [ i - 1 , 2 ] ; } } } public static void Main ( string [ ] args ) { int [ ] arr = { 9 , 5 , 7 , 6 , 9 , 0 , 0 , 0 , 0 , 5 , 6 , 7 , 3 , 9 , 0 , 7 , 0 , 9 , 0 } ; int Q = 5 ; int [ , ] query = { { 1 , 5 , 14 } , { 2 , 6 , 1 } , { 1 , 0 , 8 } , { 2 , 13 , 0 } , { 1 , 6 , 18 } } ; int N = arr . Length ; int K = 0 ; performQueries ( N , Q , K , arr , query ) ; } }
Minimum count of consecutive integers till N whose bitwise AND is 0 with N | C # program for the above approach ; Function to count the minimum count of integers such that bitwise AND of that many consecutive elements is equal to 0 ; Stores the binary representation of N ; Stores the MSB bit ; Stores the count of numbers ; Return res ; Driver Code ; Given Input ; Function Call
using System ; using System . Collections . Generic ; public class GFG { static int count ( int N ) { String a = Convert . ToString ( N , 2 ) ; int m = a . Length - 1 ; int res = ( int ) ( N - ( Math . Pow ( 2 , m ) - 1 ) ) ; return res ; } public static void Main ( String [ ] args ) { int N = 18 ; Console . WriteLine ( count ( N ) ) ; } }
Find smallest value of K such that bitwise AND of numbers in range [ N , N | C # program for the above approach ; Function is to find the largest no which gives the sequence n & ( n - 1 ) & ( n - 2 ) & ... . . & ( n - k ) = 0. ; Since , we need the largest no , we start from n itself , till 0 ; Driver code
using System ; class GFG { public static int findSmallestNumK ( int n ) { int cummAnd = n ; int i = n - 1 ; while ( cummAnd != 0 ) { cummAnd = cummAnd & i ; if ( cummAnd == 0 ) { return i ; } i -- ; } return - 1 ; } static void Main ( ) { int N = 17 ; int lastNum = findSmallestNumK ( N ) ; int K = lastNum == - 1 ? lastNum : N - lastNum ; Console . WriteLine ( K ) ; } }
Program to find the value of P ( N + r ) for a polynomial of a degree N such that P ( i ) = 1 for 1 Ã ¢ â €°¤ i Ã ¢ â €°¤ N and P ( N + 1 ) = a | C # program for the above approach ; Function to calculate factorial of N ; Base Case ; Otherwise , recursively calculate the factorial ; Function to find the value of P ( n + r ) for polynomial P ( X ) ; Stores the value of k ; Store the required answer ; Iterate in the range [ 1 , N ] and multiply ( n + r - i ) with answer ; Add the constant value C as 1 ; Return the result ; Driver Code
using System ; class GFG { static int fact ( int n ) { if ( n == 1 n == 0 ) return 1 ; else return n * fact ( n - 1 ) ; } static int findValue ( int n , int r , int a ) { int k = ( a - 1 ) / fact ( n ) ; int answer = k ; for ( int i = 1 ; i < n + 1 ; i ++ ) answer = answer * ( n + r - i ) ; answer = answer + 1 ; return answer ; } static public void Main ( ) { int N = 1 ; int A = 2 ; int R = 3 ; Console . Write ( ( findValue ( N , R , A ) ) ) ; } }
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
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 Nth number in a sequence which is not a multiple of a given number | C # program for the above approach ; Function to find Nth number not a multiple of A in range [ L , R ] ; Calculate the Nth no ; Check for the edge case ; Driver code ; Input parameters ; Function Call
using System ; class GFG { static void countNo ( int A , int N , int L , int R ) { int ans = L - 1 + N + ( ( N - 1 ) / ( A - 1 ) ) ; if ( ans % A == 0 ) { ans = ans + 1 ; } Console . WriteLine ( ans ) ; } static void Main ( ) { int A = 5 , N = 10 , L = 4 , R = 20 ; countNo ( A , N , L , R ) ; } }
Count of paths in given Binary Tree with odd bitwise AND for Q queries | C # implementation to count paths in Binary Tree with odd bitwise AND ; Function to count number of paths in binary tree such that bitwise AND of all nodes is Odd ; dp to store the count of bitwise odd paths till that vertex ; Precomputing for each value ; Check for odd value ; Number of odd elements will be + 1 till the parent node ; For even case ; Since node is even Number of odd elements will be 0 ; Even value node will not contribute in answer hence dp [ i ] = previous answer ; Printing the answer for each query ; Driver code ; To store queries
using System ; class GFG { static void compute ( int [ ] query ) { int [ ] v = new int [ 100001 ] ; int [ ] dp = new int [ 100001 ] ; v [ 1 ] = 1 ; v [ 2 ] = 0 ; dp [ 1 ] = 0 ; dp [ 2 ] = 0 ; for ( int i = 3 ; i < 100001 ; i ++ ) { if ( i % 2 != 0 ) { if ( ( i / 2 ) % 2 == 0 ) { v [ i ] = 1 ; dp [ i ] = dp [ i - 1 ] ; } else { v [ i ] = v [ i / 2 ] + 1 ; dp [ i ] = dp [ i - 1 ] + v [ i ] - 1 ; } } else { v [ i ] = 0 ; dp [ i ] = dp [ i - 1 ] ; } } foreach ( int x in query ) Console . Write ( dp [ x ] + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] query = { 5 , 2 } ; compute ( query ) ; } }
Number of cycles formed by joining vertices of n sided polygon at the center | C # program for the above approach ; Function to calculate number of cycles ; BigInteger is used here if N = 10 ^ 9 then multiply will result into value greater than 10 ^ 18 ; BigInteger multiply function ; Return the final result ; Driver code ; Given N ; Function Call
using System ; class GFG { static int findCycles ( int N ) { int res = 0 ; int finalResult = 0 ; int val = 2 * N - 1 ; int s = val ; res = ( N - 1 ) * ( N - 2 ) ; finalResult = res + s ; return finalResult ; } static void Main ( ) { int N = 5 ; Console . WriteLine ( findCycles ( N ) ) ; } }
Split a given array into K subarrays minimizing the difference between their maximum and minimum | C # program for the above approach ; Function to find the subarray ; Add the difference to vectors ; Sort vector to find minimum k ; Initialize result ; Adding first k - 1 values ; Return the minimized sum ; Driver Code ; Given array [ ] arr ; Given K ; Function Call
using System ; using System . Collections . Generic ; class GFG { static int find ( int [ ] a , int n , int k ) { List < int > v = new List < int > ( ) ; for ( int i = 1 ; i < n ; ++ i ) { v . Add ( a [ i - 1 ] - a [ i ] ) ; } v . Sort ( ) ; int res = a [ n - 1 ] - a [ 0 ] ; for ( int i = 0 ; i < k - 1 ; ++ i ) { res += v [ i ] ; } return res ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 8 , 15 , 16 , 23 , 42 } ; int N = arr . Length ; int K = 3 ; Console . Write ( find ( arr , N , K ) + " STRNEWLINE " ) ; } }
Last digit of a number raised to last digit of N factorial | C # program for the above approach ; Function to find a ^ b using binary exponentiation ; Initialise result ; If b is odd then , multiply result by a ; b must be even now Change b to b / 2 ; Change a = a ^ 2 ; Function to find the last digit of the given equation ; To store cyclicity ; Store cyclicity from 1 - 10 ; Observation 1 ; Observation 3 ; To store the last digits of factorial 2 , 3 , and 4 ; Find the last digit of X ; Step 1 ; Divide a [ N ] by cyclicity of v ; If remainder is 0 ; Step 1.1 ; Step 1.2 ; Step 1.3 ; If r is non - zero , then return ( l ^ r ) % 10 ; Else return 0 ; Else return 1 ; Driver code ; Given numbers ; Function call ; Print the result
using System ; using System . Collections . Generic ; class GFG { static long power ( long a , long b , long c ) { long result = 1 ; while ( b > 0 ) { if ( ( b & 1 ) == 1 ) { result = ( result * a ) % c ; } b /= 2 ; a = ( a * a ) % c ; } return result ; } public static long calculate ( long X , long N ) { int [ ] a = new int [ 10 ] ; int [ ] cyclicity = new int [ 11 ] ; cyclicity [ 1 ] = 1 ; cyclicity [ 2 ] = 4 ; cyclicity [ 3 ] = 4 ; cyclicity [ 4 ] = 2 ; cyclicity [ 5 ] = 1 ; cyclicity [ 6 ] = 1 ; cyclicity [ 7 ] = 4 ; cyclicity [ 8 ] = 4 ; cyclicity [ 9 ] = 2 ; cyclicity [ 10 ] = 1 ; if ( N == 0 N == 1 ) { return ( X % 10 ) ; } else if ( N == 2 N == 3 N == 4 ) { long temp = ( long ) 1e18 ; a [ 2 ] = 2 ; a [ 3 ] = 6 ; a [ 4 ] = 4 ; long v = X % 10 ; if ( v != 0 ) { int u = cyclicity [ ( int ) v ] ; int r = a [ ( int ) N ] % u ; if ( r == 0 ) { if ( v == 2 v == 4 v == 6 v == 8 ) { return 6 ; } else if ( v == 5 ) { return 5 ; } else if ( v == 1 v == 3 v == 7 v == 9 ) { return 1 ; } } else { return ( power ( v , r , temp ) % 10 ) ; } } else { return 0 ; } } return 1 ; } static void Main ( ) { int X = 18 ; int N = 4 ; long result = calculate ( X , N ) ; Console . Write ( result ) ; } }
Maximize 3 rd element sum in quadruplet sets formed from given Array | C # code to maximize 3 rd element sum in quadruplet sets formed from given Array ; Function to find the maximum possible value of Y ; Pairs contain count of minimum elements that will be utilized at place of Z . It is equal to count of possible pairs that is size of array divided by 4 ; Sorting the array in descending order so as to bring values with minimal difference closer to arr [ i ] ; Here , i + 2 acts as a pointer that points to the third value of every possible quadruplet ; Returning the optimally maximum possible value ; Driver code ; Array declaration ; Size of array
using System ; class GFG { static int formQuadruplets ( int [ ] arr , int n ) { int ans = 0 , pairs = 0 ; pairs = n / 4 ; Array . Sort ( arr ) ; Array . Reverse ( arr ) ; for ( int i = 0 ; i < n - pairs ; i += 3 ) { ans += arr [ i + 2 ] ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 1 , 7 , 5 , 5 , 4 , 1 , 1 , 3 , 3 , 2 , 2 } ; int n = arr . Length ; Console . Write ( formQuadruplets ( arr , n ) + " STRNEWLINE " ) ; } }