codeparrot/xlcost-text-to-code huggingface dataset:
Smallest multiple of N with exactly N digits in its Binary number representation | C # program to find smallest multiple of n with exactly N digits in Binary Number System . ; Function to find smallest multiple of n with exactly N digits in Binary Number System . ; Driver code
using System ; class GFG { static void smallestNumber ( int N ) { Console . Write ( N * Math . Ceiling ( Math . Pow ( 2 , ( N - 1 ) ) / N ) ) ; } public static void Main ( string [ ] args ) { int N = 3 ; smallestNumber ( N ) ; } }
Find the largest N digit multiple of N | C # program to find largest multiple of N containing N digits ; Function to find the largest N digit multiple of N ; Driver code
using System ; class GFG { static void smallestNumber ( int N ) { Console . Write ( N * Math . Floor ( ( Math . Pow ( 10 , N ) - 1 ) / N ) ) ; } public static void Main ( ) { int N = 2 ; smallestNumber ( N ) ; } }
Icosikaiheptagonal Number | C # program to find N - th icosikaiheptagonal number ; Function to find the nth icosikaiheptagonal number ; Driver code
using System ; class GFG { static int icosikaiheptagonal ( int n ) { return ( 25 * n * n - 23 * n ) / 2 ; } public static void Main ( String [ ] args ) { int n = 3 ; Console . Write ( "3rd ▁ icosikaiheptagonal ▁ Number ▁ is ▁ " + icosikaiheptagonal ( n ) ) ; } }
Program to check if N is a triacontagonal number | C # program to check whether a number is an triacontagonal number or not ; Function to check whether a number is an triacontagonal number or not ; Condition to check whether a number is an triacontagonal number or not ; Driver code ; Given number ; Function call
using System ; class GFG { static bool istriacontagonal ( int N ) { float n = ( float ) ( ( 26 + Math . Sqrt ( 224 * N + 676 ) ) / 56 ) ; return ( n - ( int ) n ) == 0 ; } public static void Main ( String [ ] args ) { int N = 30 ; if ( istriacontagonal ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Parity of the given mathematical expression using given N numbers | C # program to determine the parity of the given mathematical expression ; Iterating through the given integers ; If any odd number is present , then S is even parity ; Else , S is odd parity ; Driver code
using System ; public class GFG { static void getParity ( int n , int [ ] A ) { foreach ( int x in A ) { if ( ( x & 1 ) == 1 ) { Console . WriteLine ( " Even " ) ; return ; } } Console . WriteLine ( " Odd " ) ; } public static void Main ( string [ ] args ) { int N = 3 ; int [ ] A = { 2 , 3 , 1 } ; getParity ( N , A ) ; } }
Count of digits after concatenation of first N positive integers | C # program to find the number of digits after concatenating the first N positive integers ; Function to find the number of digits after concatenating the first N positive integers ; Driver code
using System ; class GFG { static void numberOfDigits ( int N ) { int nod = ( int ) Math . Floor ( Math . Log10 ( N ) + 1 ) ; int toDecrease = ( int ) ( Math . Pow ( 10 , nod ) - 1 ) / 9 ; Console . Write ( ( N + 1 ) * nod - toDecrease ) ; } public static void Main ( ) { int N = 13 ; numberOfDigits ( N ) ; } }
Length of maximum product subarray | C # program to find maximum length subarray having non zero product ; Function that returns the maximum length subarray having non zero product ; zeroindex list to store indexex of zero ; If zeroindex list is empty then Maxlength is as size of array ; If zeroindex list is not empty ; first zero is on index 2 that means two numbers positive , before index 2 so as their product is positive to ; Checking for other indexex ; If the difference is greater than maxlen then maxlen is updated ; To check the length of remaining array after last zeroindex ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void Maxlength ( int [ ] arr , int N ) { int [ ] zeroindex = new int [ 20000 ] ; int maxlen ; int size = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) zeroindex [ size ++ ] = i ; } if ( size == 0 ) { maxlen = N ; } else { maxlen = zeroindex [ 0 ] ; for ( int i = 0 ; i < size ; i ++ ) { if ( zeroindex [ i + 1 ] - zeroindex [ i ] - 1 > maxlen ) { maxlen = zeroindex [ i + 1 ] - zeroindex [ i ] - 1 ; } } if ( N - zeroindex [ size - 1 ] - 1 > maxlen ) { maxlen = N - zeroindex [ size - 1 ] - 1 ; } } Console . WriteLine ( maxlen ) ; } public static void Main ( ) { int N = 9 ; int [ ] arr = { 7 , 1 , 0 , 1 , 2 , 0 , 9 , 2 , 1 } ; Maxlength ( arr , N ) ; } }
Check if sum of exactly K elements of the Array can be odd or not | C # implementation of the above approach ; Function returns true if it is possible to have odd sum ; Counting number of odd and even elements ; Driver code
using System ; class GFG { static bool isPossible ( int [ ] arr , int N , int K ) { int oddCount = 0 , evenCount = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { evenCount ++ ; } else { oddCount ++ ; } } if ( evenCount == N || ( oddCount == N && K % 2 == 0 ) || ( K == N && oddCount % 2 == 0 ) ) { return false ; } else { return true ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 8 } ; int K = 5 ; int N = arr . Length ; if ( isPossible ( arr , N , K ) ) { Console . WriteLine ( " Possible " ) ; } else { Console . WriteLine ( " Not ▁ Possible " ) ; } } }
Find the last two digits of Factorial of a given Number | C # implementation to find last two digits factorial of a given number ; Function to print the last two digits of N ! ; For N >= 10 , N ! % 100 will always be 0 ; Calculating N ! % 100 ; Driver code
using System ; class GFG { static void lastTwoDigits ( double N ) { if ( N >= 10 ) { Console . Write ( "00" ) ; return ; } double fac = 1 ; for ( int i = 1 ; i <= N ; i ++ ) fac = ( fac * i ) % 100 ; Console . Write ( fac ) ; } public static void Main ( ) { int N = 7 ; lastTwoDigits ( N ) ; } }
Product of N terms of a given Geometric series | C # program for the above approach ; Function to calculate product of geometric series ; Return the final product with the above formula ; Driver Code ; Given first term and common ratio ; Number of terms ; Function Call
using System ; class GFG { static float productOfGP ( float a , float r , int n ) { return ( float ) Math . Pow ( a , n ) * ( float ) Math . Pow ( r , n * ( n - 1 ) / 2 ) ; } public static void Main ( String [ ] args ) { float a = 1 , r = 2 ; int N = 4 ; Console . WriteLine ( productOfGP ( a , r , N ) ) ; } }
Product of N terms of a given Geometric series | C # program for the above approach ; Function to calculate product of N terms of geometric series ; Find the product of first and the last term ; Return the sqrt of the above expression to find the product ; Driver Code ; Given first term and common ratio ; Number of terms ; Function Call
using System ; class GFG { static float productOfGP ( float a , float r , int n ) { int an = ( int ) ( a * ( int ) ( Math . Pow ( r , n - 1 ) ) ) ; return ( int ) Math . Sqrt ( ( int ) Math . Pow ( a * an , n ) ) ; } public static void Main ( ) { float a = 1 , r = 2 ; int N = 4 ; Console . Write ( productOfGP ( a , r , N ) ) ; } }
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
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 ) ; } }
Probability that an arbitrary positive divisor of 10 ^ X is an integral multiple of 10 ^ Y | C # program to find the probability of an arbitrary positive divisor of Xth power of 10 to be a multiple of Yth power of 10 ; Function to calculate and print the required probability ; Count of potential divisors of X - th power of 10 which are also multiples of Y - th power of 10 ; Count of divisors of X - th power of 10 ; Calculate GCD ; Print the reduced fraction probability ; Driver code
using System ; class GFG { static void prob ( int x , int y ) { int num = Math . Abs ( x - y + 1 ) * Math . Abs ( x - y + 1 ) ; int den = ( x + 1 ) * ( x + 1 ) ; int gcd = __gcd ( num , den ) ; Console . Write ( num / gcd + " / " + den / gcd + " STRNEWLINE " ) ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void Main ( string [ ] args ) { int X = 2 , Y = 1 ; prob ( X , Y ) ; } }
Program to check if N is a Chiliagon Number | C # program for the above approach ; Function to check that if N is Chiliagon Number or not ; Condition to check if N is a Chiliagon Number ; Driver Code ; Given Number ; Function call
using System ; class GFG { static bool is_Chiliagon ( int N ) { float n = ( float ) ( 996 + Math . Sqrt ( 7984 * N + 992016 ) ) / 1996 ; return ( n - ( int ) n ) == 0 ; } public static void Main ( ) { int N = 1000 ; if ( is_Chiliagon ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Count of common subarrays in two different permutations of 1 to N | C # implementation of the above approach ; Initialising Map for Index Mapping ; Mapping elements of A ; Modify elements of B according to Map ; Changing B [ i ] as the index of B [ i ] in A ; Count of common subarrays ; Traversing array B ; While consecutive elements are found , we increment K ; Add number of subarrays with length K to total count ; Driver code
using System ; class GFG { static int commonSubarrays ( int [ ] A , int [ ] B , int N ) { int [ ] Map = new int [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) Map [ A [ i ] ] = i ; for ( int i = 0 ; i < N ; i ++ ) { B [ i ] = Map [ B [ i ] ] ; } int count = 0 ; int a = 0 , K ; while ( a < N ) { K = 1 ; a += 1 ; while ( a < N && B [ a ] == B [ a - 1 ] + 1 ) { a += 1 ; K += 1 ; } count = count + ( ( K ) * ( K + 1 ) ) / 2 ; } return count ; } public static void Main ( ) { int N = 3 ; int [ ] A = { 1 , 2 , 3 } ; int [ ] B = { 2 , 3 , 1 } ; Console . Write ( commonSubarrays ( A , B , N ) ) ; Console . Write ( " STRNEWLINE " ) ; N = 5 ; int [ ] C = { 1 , 2 , 3 , 4 , 5 } ; int [ ] D = { 2 , 3 , 1 , 4 , 5 } ; Console . Write ( commonSubarrays ( C , D , N ) ) ; } }
Represent N as sum of K even or K odd numbers with repetitions allowed | C # implementation to find an array of size K with all the even or odd elements in the array ; Function to find the array with all the even / odd elements ; First let 's check  kth is odd or even ; If last element is also an odd number then we can choose odd elements for our answer ; Add 1 in the array ( k - 1 ) times ; Add last odd element ; If array of even elements would be the answer then k - 1 elements would be 2 ; If last element is also an even number then we can choose even elements for our answer ; Add 2 in the array ( k - 1 ) times ; Add last even element ; Printing the array ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void getArrayOfSizeK ( int n , int k ) { List < int > ans = new List < int > ( ) ; int odd = n - ( ( k - 1 ) * 1 ) ; if ( odd > 0 && odd % 2 != 0 ) { for ( int i = 0 ; i < k - 1 ; i ++ ) { ans . Add ( 1 ) ; } ans . Add ( odd ) ; } int even = n - ( ( k - 1 ) * 2 ) ; if ( even > 0 && even % 2 == 0 && ans . Count == 0 ) { for ( int i = 0 ; i < k - 1 ; i ++ ) { ans . Add ( 2 ) ; } ans . Add ( even ) ; } if ( ans . Count > 0 ) { for ( int i = 0 ; i < k ; i ++ ) { Console . Write ( ans [ i ] + " ▁ " ) ; } } else { Console . WriteLine ( " NO " ) ; } } public static void Main ( String [ ] args ) { int n = 10 , k = 3 ; getArrayOfSizeK ( n , k ) ; } }
Check whether a given number N is a Nude Number or not | C # program to check if the number if Nude number or not ; Check if all digits of num divide num ; array to store all digits of the given number ; If any of the condition is true for any digit Then N is not a nude number ; Driver code
using System ; class GFG { static bool checkDivisbility ( int num ) { int digit ; int N = num ; while ( num != 0 ) { digit = num % 10 ; num = num / 10 ; if ( digit == 0 N % digit != 0 ) return false ; } return true ; } public static void Main ( ) { int N = 128 ; bool result = checkDivisbility ( N ) ; if ( result ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Hensel 's Lemma | C # program to illustrate the Hensel 's Lemma ; Function to find the modular inverse of a modulo m ; Apply the Euclidean algorithm , to find the modular inverse ; Function to find the derivative of f ( x ) and f '(x) = 3 * (x ^ 2) ; Function to find the image of x in f ( x ) = x ^ 3 - k . ; Function to find the next power of the number ; Next power of prime for which solution is to be found ; Using Hensel 's recursion to  find the solution (next_a) for  next power of prime ; If next_a < 0 return equivalent positive remainder modulo p ; Return the next power of a ; Function to find the solution of the required exponent of prime ; The lemma does not work for derivative of f ( x ) at a1 ; Looping from 1 to power of prime whose solution is to be found ; Final answer after evaluating all the exponents up till the required exponent ; Driver Code ; Function Call
using System ; class GFG { static int inv ( int a , int m ) { int m0 = m , t , q ; int x0 = 0 , x1 = 1 ; if ( m == 1 ) return 0 ; while ( a > 1 ) { q = a / m ; t = m ; m = a % m ; a = t ; t = x0 ; x0 = x1 - q * x0 ; x1 = t ; } if ( x1 < 0 ) x1 += m0 ; return x1 ; } static int derivative ( int x ) { return 3 * x * x ; } static int Image ( int x , int k ) { return x * x * x - k ; } static int next_power ( int a_t , int t , int a1 , int prime , int k ) { int power_p = ( int ) Math . Pow ( prime , t + 1 ) ; int next_a = ( a_t - Image ( a_t , k ) * inv ( derivative ( a1 ) , prime ) ) % power_p ; if ( next_a < 0 ) return next_a += power_p ; return next_a ; } static int powerOfPrime ( int prime , int power , int k , int a1 ) { if ( derivative ( a1 ) != 0 ) { int a_t = a1 ; for ( int p = 1 ; p < power ; p ++ ) { a_t = next_power ( a_t , p , a1 , prime , k ) ; } return a_t ; } return - 1 ; } public static void Main ( string [ ] args ) { int prime = 7 , a1 = 3 ; int power = 2 , k = 3 ; Console . Write ( powerOfPrime ( prime , power , k , a1 ) ) ; } }
Count of numbers with all digits same in a given range | C # program to count the total numbers in the range L and R which have all the digit same ; Function that count the total numbersProgram between L and R which have all the digit same ; Length of R ; tmp has all digits as 1 ; For each multiple of tmp in range 1 to 9 , check if it present in range [ L , R ] ; Increment the required count ; Driver code
using System ; class GFG { static int count_same_digit ( int L , int R ) { int tmp = 0 , ans = 0 ; int n = ( int ) Math . Log10 ( R ) + 1 ; for ( int i = 0 ; i < n ; i ++ ) { tmp = tmp * 10 + 1 ; for ( int j = 1 ; j <= 9 ; j ++ ) { if ( L <= ( tmp * j ) && ( tmp * j ) <= R ) { ans ++ ; } } } return ans ; } public static void Main ( ) { int L = 12 , R = 68 ; Console . Write ( count_same_digit ( L , R ) ) ; } }
Minimum LCM of all pairs in a given array | C # program to find the pair having minimum LCM ; Function that return pair having minimum LCM ; Find max element in the array as the gcd of two elements from the array can 't greater than max element. ; Created a 2D array to store minimum two multiple of any particular i . ; We already found two smallest multiple ; Iterating over all gcd ; Iterating over its multiple ; If we already found the two smallest multiple of i ; Choosing smallest two multiple ; Calculating lcm ; Return readonly answer ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int minLCM ( int [ ] arr , int n ) { int mx = 0 ; for ( int i = 0 ; i < n ; i ++ ) { mx = Math . Max ( mx , arr [ i ] ) ; } List < int > [ ] mul = new List < int > [ mx + 1 ] ; for ( int i = 0 ; i < mul . Length ; i ++ ) mul [ i ] = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mul [ arr [ i ] ] . Count > 1 ) { continue ; } mul [ arr [ i ] ] . Add ( arr [ i ] ) ; } for ( int i = 1 ; i <= mx ; i ++ ) { for ( int j = i + i ; j <= mx ; j += i ) { if ( mul [ i ] . Count > 1 ) { break ; } foreach ( int k in mul [ j ] ) { if ( mul [ i ] . Count > 1 ) break ; mul [ i ] . Add ( k ) ; } } } int ans = int . MaxValue ; for ( int i = 1 ; i <= mx ; i ++ ) { if ( mul [ i ] . Count <= 1 ) continue ; int a = mul [ i ] [ 0 ] , b = mul [ i ] [ 1 ] ; int lcm = ( a * b ) / i ; ans = Math . Min ( ans , lcm ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 4 , 3 , 6 , 5 } ; int n = arr . Length ; Console . Write ( minLCM ( arr , n ) + " STRNEWLINE " ) ; } }
Count of triplets of numbers 1 to N such that middle element is always largest | C # program to implement the above approach ; Function to find number of triplets for given number N such that middle element is always greater than left and right side element . ; Check if arrangement is possible or not ; Else return total ways ; Driver code
using System ; class GFG { static int findArrangement ( int N ) { if ( N < 3 ) return 0 ; return ( ( N ) * ( N - 1 ) * ( N - 2 ) ) / 3 ; } public static void Main ( ) { int N = 10 ; Console . Write ( findArrangement ( N ) ) ; } }
Sum of all perfect square divisors of numbers from 1 to N | C # program to find the sum of all perfect square divisors of numbers from 1 to N ; Function for finding inverse of a number iteratively Here we will find the inverse of 6 , since it appears as denominator in the formula of sum of squares from 1 to N ; Store the value of the inverse of 6 once as we don 't need to call the function again and again ; Formula for finding the sum of first n squares ; No perfect square exists which is less than 4 ; Starting from 2 , present value of start is denoted here as curStart ; Finding end of the segment for which the contribution will be same ; Using the above mentioned formula to find ans % MOD ; Now for mthe next iteration start will become end + 1 ; Finally returning the answer ; Driver Code ; Here we are adding x because we have not counted 1 as perfect squares so if u want to add it you can just add that number to the ans
using System ; class GFG { static readonly int MOD = 7 ; static int inv ( int a ) { int o = 1 ; for ( int p = MOD - 2 ; p > 0 ; p >>= 1 ) { if ( ( p & 1 ) == 1 ) o = ( o * a ) % MOD ; a = ( a * a ) % MOD ; } return o ; } static int inv6 = inv ( 6 ) ; static int sumOfSquares ( int n ) { n %= MOD ; return ( ( ( n * ( n + 1 ) ) % MOD * ( 2 * n + 1 ) ) % MOD * inv6 ) % MOD ; } static int sums ( int n ) { if ( n < 4 ) return 0 ; int curStart = 2 , ans = 0 ; int sqrtN = ( int ) Math . Sqrt ( n ) ; while ( curStart <= n / curStart ) { int V = n / ( curStart * curStart ) ; int end = ( int ) Math . Sqrt ( n / V ) ; ans += ( n / ( curStart * curStart ) % MOD * ( sumOfSquares ( end ) + MOD - sumOfSquares ( curStart - 1 ) ) ) % MOD ; if ( ans >= MOD ) ans -= MOD ; curStart = end + 1 ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] input = { 5 } ; foreach ( int x in input ) { Console . Write ( " sum ▁ of ▁ all ▁ perfect ▁ " + " square ▁ divisors ▁ from ▁ " + "1 ▁ to ▁ " + x + " ▁ is : ▁ " ) ; Console . Write ( x + sums ( x ) + " STRNEWLINE " ) ; } } }
Check whether the binary equivalent of a number ends with "001" or not | C # implementation of the above approach ; Function returns true if s1 is suffix of s2 ; Function to check if binary equivalent of a number ends in "001" or not ; To store the binary number ; Count used to store exponent value ; Driver code
using System ; class GFG { static bool isSuffix ( string s1 , string s2 ) { int n1 = s1 . Length ; int n2 = s2 . Length ; if ( n1 > n2 ) return false ; for ( int i = 0 ; i < n1 ; i ++ ) if ( s1 [ n1 - i - 1 ] != s2 [ n2 - i - 1 ] ) return false ; return true ; } static bool CheckBinaryEquivalent ( int N ) { int B_Number = 0 ; int cnt = 0 ; while ( N != 0 ) { int rem = N % 2 ; int c = ( int ) Math . Pow ( 10 , cnt ) ; B_Number += rem * c ; N /= 2 ; cnt ++ ; } string bin = B_Number . ToString ( ) ; return isSuffix ( "001" , bin ) ; } public static void Main ( string [ ] args ) { int N = 9 ; if ( CheckBinaryEquivalent ( N ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Check whether the binary equivalent of a number ends with "001" or not | C # implementation of the above approach ; Function to check if binary equivalent of a number ends in "001" or not ; To check if binary equivalent of a number ends in "001" or not ; Driver code
using System ; class GFG { static bool CheckBinaryEquivalent ( int N ) { return ( N - 1 ) % 8 == 0 ; } public static void Main ( string [ ] args ) { int N = 9 ; if ( CheckBinaryEquivalent ( N ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Panarithmic numbers within a given range | C # program to print practical Numbers in given range ; Function to compute divisors of a number ; To store divisors ; 1 will always be a divisor ; Check if i is squareroot of A then only one time insert it in ans ; Function to check that a number can be represented as sum of distinct divisor or not ; The value of subset [ i ] [ j ] will be true if there is a subset of set [ 0. . j - 1 ] with sum equal to i ; If sum is 0 , then answer is true ; If sum is not 0 and set is empty , then answer is false ; Fill the subset table in bottom up manner ; Return the possibility of given sum ; Function to check a number is Practical or not ; To store divisors ; If all numbers can be represented as sum of unique divisors ; Function to print Practical Numbers in a range ; Driver code
using System ; using System . Collections ; class GFG { static ArrayList get_divisors ( int A ) { ArrayList ans = new ArrayList ( ) ; ans . Add ( 1 ) ; for ( int i = 2 ; i <= ( int ) Math . Sqrt ( A ) ; i ++ ) { if ( A % i == 0 ) { ans . Add ( i ) ; if ( ( i * i ) != A ) ans . Add ( A / i ) ; } } return ans ; } static bool Sum_Possible ( ArrayList set , int sum ) { int n = set . Count ; bool [ , ] subset = new bool [ n + 1 , sum + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) subset [ i , 0 ] = true ; for ( int i = 1 ; i <= sum ; i ++ ) subset [ 0 , i ] = false ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( j < ( int ) set [ i - 1 ] ) subset [ i , j ] = subset [ i - 1 , j ] ; if ( j >= ( int ) set [ i - 1 ] ) subset [ i , j ] = subset [ i - 1 , j ] || subset [ i - 1 , j - ( int ) set [ i - 1 ] ] ; } } return subset [ n , sum ] ; } static bool Is_Practical ( int A ) { ArrayList divisors = new ArrayList ( ) ; divisors = get_divisors ( A ) ; for ( int i = 2 ; i < A ; i ++ ) { if ( Sum_Possible ( divisors , i ) == false ) return false ; } return true ; } static void print_practica_No ( int A , int B ) { for ( int i = A ; i <= B ; i ++ ) { if ( Is_Practical ( i ) == true ) { Console . Write ( i + " ▁ " ) ; } } } public static void Main ( string [ ] args ) { int A = 1 , B = 100 ; print_practica_No ( A , B ) ; } }
Maximize the division result of Array using given operations | C # implementation to maximize the result of division of the given array elements ; Function to find the max result ; Sort the array in descending order ; Loop to divide in this order arr [ 0 ] / ( arr [ 1 ] / arr [ 2 ] / ... . arr [ n - 2 ] / arr [ n - 1 ] ) ; Return the readonly result ; Driver code
using System ; class GFG { static float maxDivision ( int [ ] arr , int n ) { Array . Sort ( arr ) ; Array . Reverse ( arr ) ; float mxdiv = arr [ 1 ] ; for ( int i = 2 ; i < n ; ++ i ) mxdiv = mxdiv / arr [ i ] ; return arr [ 0 ] / mxdiv ; } public static void Main ( String [ ] args ) { int [ ] arr = { 100 , 1000 , 10 , 2 } ; int n = arr . Length ; Console . Write ( ( int ) maxDivision ( arr , n ) ) ; } }