codeparrot/xlcost-text-to-code huggingface dataset:
Count integers up to N which can be represented as sum of two or more consecutive numbers | C # program for the above approach ; Function to check if the number N can be expressed as sum of 2 or more consecutive numbers or not ; Function to count integers in the range [ 1 , N ] that can be expressed as sum of 2 or more consecutive numbers ; Stores the required count ; Driver Code
using System ; class GFG { static int isPossible ( int N ) { return ( ( ( N & ( N - 1 ) ) & N ) ) ; } static void countElements ( int N ) { int count = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( isPossible ( i ) != 0 ) count ++ ; } Console . Write ( count ) ; } static public void Main ( ) { int N = 15 ; countElements ( N ) ; } }
Count integers up to N which can be represented as sum of two or more consecutive numbers | C # implementation of the above approach ; Function to count integers in the range [ 1 , N ] that can be expressed as sum of 2 or more consecutive numbers ; Count powers of 2 up to N ; Increment count ; Update current power of 2 ; Driver Code
using System ; public class GFG { static void countElements ( int N ) { int Cur_Ele = 1 ; int Count = 0 ; while ( Cur_Ele <= N ) { Count ++ ; Cur_Ele = Cur_Ele * 2 ; } Console . Write ( N - Count ) ; } public static void Main ( String [ ] args ) { int N = 15 ; countElements ( N ) ; } }
Maximum difference between a pair of adjacent elements by excluding every element once | C # Program to implement the above approach ; Function to calculate maximum difference between adjacent elements excluding every array element once ; Compute maximum adjacent difference for whole array ; Store the maximum between arr_max and curr_max ; Append the result into a vector ; Print the result ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void maxAdjacent ( int [ ] arr , int N ) { List < int > res = new List < int > ( ) ; int arr_max = Int32 . MinValue ; for ( int i = 1 ; i < N ; i ++ ) { arr_max = Math . Max ( arr_max , Math . Abs ( arr [ i - 1 ] - arr [ i ] ) ) ; } for ( int i = 1 ; i < N - 1 ; i ++ ) { int curr_max = Math . Abs ( arr [ i - 1 ] - arr [ i + 1 ] ) ; int ans = Math . Max ( curr_max , arr_max ) ; res . Add ( ans ) ; } foreach ( int x in res ) Console . Write ( x + " ▁ " ) ; Console . WriteLine ( ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 4 , 7 , 8 } ; int N = arr . Length ; maxAdjacent ( arr , N ) ; } }
Minimize increments required to make count of even and odd array elements equal | C # program to implement the above approach ; Function to find min operations to make even and odd count equal ; Odd size will never make odd and even counts equal ; Stores the count of even numbers in the array arr [ ] ; Stores count of odd numbers in the array arr [ ] ; Traverse the array arr [ ] ; If arr [ i ] is an even number ; Update cntEven ; Odd numbers in arr [ ] ; Return absolute difference divided by 2 ; Driver Code ; Function call
using System ; class GFG { static int minimumIncrement ( int [ ] arr , int N ) { if ( N % 2 != 0 ) { Console . WriteLine ( " - 1" ) ; Environment . Exit ( 0 ) ; } int cntEven = 0 ; int cntOdd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { cntEven += 1 ; } } cntOdd = N - cntEven ; return Math . Abs ( cntEven - cntOdd ) / 2 ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , 4 , 9 } ; int N = arr . Length ; Console . WriteLine ( minimumIncrement ( arr , N ) ) ; } }
Count ways to construct array with even product from given array such that absolute difference of same indexed elements is at most 1 | C # program to implement the above approach ; Function to find count the ways to construct an array , [ ] B such that abs ( A [ i ] - B [ i ] ) <= 1 and product of elements of [ ] B is even ; Stores count of arrays [ ] B such that abs ( A [ i ] - B [ i ] ) <= 1 ; Stores count of arrays [ ] B whose product of elements is not even ; Traverse the array ; Update total ; If A [ i ] is an even number ; Update oddArray ; Print 3 ^ N - 2 ^ X ; Driver Code
using System ; class GFG { static void cntWaysConsArray ( int [ ] A , int N ) { int total = 1 ; int oddArray = 1 ; for ( int i = 0 ; i < N ; i ++ ) { total = total * 3 ; if ( A [ i ] % 2 == 0 ) { oddArray *= 2 ; } } Console . WriteLine ( total - oddArray ) ; } public static void Main ( String [ ] args ) { int [ ] A = { 2 , 4 } ; int N = A . Length ; cntWaysConsArray ( A , N ) ; } }
Count numbers up to N whose rightmost set bit is K | C # program for the above approach ; Function to count the numbers in the range [ 1 , N ] whose rightmost set bit is K ; Stores the number whose rightmost set bit is K ; Numbers whose rightmost set bit is i ; Subtracting the number whose rightmost set bit is i , from N ; Since i = k , then the number whose rightmost set bit is K is stored ; Driver Code
using System ; class GFG { static void countNumberHavingKthBitSet ( int N , int K ) { int numbers_rightmost_setbit_K = 0 ; for ( int i = 1 ; i <= K ; i ++ ) { int numbers_rightmost_bit_i = ( N + 1 ) / 2 ; N -= numbers_rightmost_bit_i ; if ( i == K ) { numbers_rightmost_setbit_K = numbers_rightmost_bit_i ; } } Console . WriteLine ( numbers_rightmost_setbit_K ) ; } static public void Main ( String [ ] args ) { int N = 15 ; int K = 2 ; countNumberHavingKthBitSet ( N , K ) ; } }
Count odd and even Binomial Coefficients of N | C # program for the above approach ; Function to count set bits in binary representation of number N ; Count set bits in N ; Return the final count ; Driver Code ; Print odd Binomial coefficients ; Print even Binomial coefficients
using System ; class GFG { static int countSetBits ( int N ) { int count = 0 ; while ( N != 0 ) { N = N & ( N - 1 ) ; count ++ ; } return count ; } public static void Main ( ) { int N = 4 ; int bits = countSetBits ( N ) ; Console . WriteLine ( " Odd ▁ " + " : ▁ " + ( int ) ( Math . Pow ( 2 , bits ) ) ) ; Console . WriteLine ( " Even ▁ " + " : ▁ " + ( N + 1 - ( int ) ( Math . Pow ( 2 , bits ) ) ) ) ; } }
Make all array elements even by replacing any pair of array elements with their sum | C # program for the above approach ; Function to find the minimum number of replacements required to make all array elements even ; Stores the count of odd elements ; Traverse the array ; Increase count of odd elements ; Store number of replacements required ; Two extra moves will be required to make the last odd element even ; Print the minimum replacements ; Driver Code ; Function call
using System ; public class GFG { static void minMoves ( int [ ] arr , int N ) { int odd_element_cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 != 0 ) { odd_element_cnt ++ ; } } int moves = ( odd_element_cnt ) / 2 ; if ( odd_element_cnt % 2 != 0 ) moves += 2 ; Console . Write ( moves ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 6 , 3 , 7 , 20 } ; int N = arr . Length ; minMoves ( arr , N ) ; } }
Split squares of first N natural numbers into two sets with minimum absolute difference of their sums | C # program for the above approach ; Function to partition squares of N natural number in two subset ; Store the count of blocks of size 8 ; Partition of block of 8 element ; Store the minimum subset difference ; Partition of N elements to minimize their subset sum difference ; Store elements of subset A and B ; If element is of type A ; If the element is of type B ; Print the minimum subset difference ; Print the first subset ; Print the second subset ; Driver Code ; Function Call
using System ; class GFG { static void minimumSubsetDifference ( int N ) { int blockOfSize8 = N / 8 ; string str = " ABBABAAB " ; int subsetDifference = 0 ; string partition = " " ; while ( blockOfSize8 -- > 0 ) { partition += str ; } int [ ] A = new int [ N ] ; int [ ] B = new int [ N ] ; int x = 0 , y = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( partition [ i ] == ' A ' ) { A [ x ++ ] = ( ( i + 1 ) * ( i + 1 ) ) ; } else { B [ y ++ ] = ( ( i + 1 ) * ( i + 1 ) ) ; } } Console . WriteLine ( subsetDifference ) ; for ( int i = 0 ; i < x ; i ++ ) Console . Write ( A [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; for ( int i = 0 ; i < y ; i ++ ) Console . Write ( B [ i ] + " ▁ " ) ; } public static void Main ( string [ ] args ) { int N = 8 ; minimumSubsetDifference ( N ) ; } }
Largest divisor of a number not divisible by another given number | C # program to implement the above approach ; Function to find the largest number X such that it divides P but is not divisible by Q ; Stores the frequency count of of all Prime Factors ; Increment the frequency of the current prime factor ; If Q is a prime factor ; Stores the desired result ; Iterate through all divisors of Q ; Stores the frequency count of current prime divisor on dividing P ; Count the frequency of the current prime factor ; If cur is less than frequency then P is the final result ; Iterate to get temporary answer ; Update current answer ; Print the desired result ; Driver Code ; Given P and Q ; Function Call
using System . Collections . Generic ; using System ; using System . Linq ; class GFG { static void findTheGreatestX ( int P , int Q ) { Dictionary < int , int > divisers = new Dictionary < int , int > ( ) ; for ( int i = 2 ; i * i <= Q ; i ++ ) { while ( Q % i == 0 && Q > 1 ) { Q /= i ; if ( divisers . ContainsKey ( i ) ) divisers [ i ] ++ ; else divisers [ i ] = 1 ; } } if ( Q > 1 ) { if ( divisers . ContainsKey ( Q ) ) divisers [ Q ] ++ ; else divisers [ Q ] = 1 ; } int ans = 0 ; var val = divisers . Keys . ToList ( ) ; foreach ( var key in val ) { int frequency = divisers [ key ] ; int temp = P ; int cur = 0 ; while ( temp % key == 0 ) { temp /= key ; cur ++ ; } if ( cur < frequency ) { ans = P ; break ; } temp = P ; for ( int j = cur ; j >= frequency ; j -- ) { temp /= key ; } ans = Math . Max ( temp , ans ) ; } Console . WriteLine ( ans ) ; } public static void Main ( String [ ] args ) { int P = 10 , Q = 4 ; findTheGreatestX ( P , Q ) ; } }
Check if rows of a Matrix can be rearranged to make Bitwise XOR of first column non | C # program for the above approach ; Function to check if there is any row where number of unique elements are greater than 1 ; Iterate over the matrix ; Function to check if it is possible to rearrange [ , ] mat such that XOR of its first column is non - zero ; Find bitwise XOR of the first column of [ , ] mat ; If bitwise XOR of the first column of [ , ] mat is non - zero ; Otherwise check rearrangements ; Driver Code ; Given Matrix [ , ] mat ; Function Call
using System ; class GFG { static String checkRearrangements ( int [ , ] mat , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 1 ; j < M ; j ++ ) { if ( mat [ i , 0 ] != mat [ i , j ] ) { return " Yes " ; } } } return " No " ; } static String nonZeroXor ( int [ , ] mat , int N , int M ) { int res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { res = res ^ mat [ i , 0 ] ; } if ( res != 0 ) return " Yes " ; else return checkRearrangements ( mat , N , M ) ; } public static void Main ( String [ ] args ) { int [ , ] mat = { { 1 , 1 , 2 } , { 2 , 2 , 2 } , { 3 , 3 , 3 } } ; int N = mat . GetLength ( 0 ) ; int M = mat . GetLength ( 1 ) ; Console . Write ( nonZeroXor ( mat , N , M ) ) ; } }
Maximize Bitwise AND of first element with complement of remaining elements for any permutation of given Array | C # Program to implement the above approach ; Function to maximize the value for the given function and the array elements ; List array to maintain which bit is set for which integer in the given array by saving index of that integer ; Check if j - th bit is set for i - th integer ; Push the index of that integer in setBit [ j ] ; Find the element having highest significant set bit unset in other elements ; Place that integer at 0 - th index ; Store the maximum AND value ; Return the answer ; Driver Code ; Function call
using System ; using System . Collections . Generic ; class GFG { static readonly int size_int = 32 ; static int functionMax ( int [ ] arr , int n ) { List < int > [ ] setBit = new List < int > [ 32 + 1 ] ; for ( int i = 0 ; i < setBit . Length ; i ++ ) setBit [ i ] = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < size_int ; j ++ ) { if ( ( arr [ i ] & ( 1 << j ) ) > 0 ) setBit [ j ] . Add ( i ) ; } } for ( int i = size_int ; i >= 0 ; i -- ) { if ( setBit [ i ] . Count == 1 ) { swap ( arr , 0 , setBit [ i ] [ 0 ] ) ; break ; } } int maxAnd = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { maxAnd = maxAnd & ( ~ arr [ i ] ) ; } return maxAnd ; } static int [ ] swap ( int [ ] arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 4 , 8 , 16 } ; int n = arr . Length ; Console . Write ( functionMax ( arr , n ) ) ; } }
Sum of all products of the Binomial Coefficients of two numbers up to K | C # implementation of the above approach ; Function returns nCr i . e . Binomial Coefficient ; Initialize res with 1 ; Since C ( n , r ) = C ( n , n - r ) ; Evaluating expression ; Function to calculate and return the sum of the products ; Initialize sum to 0 ; Traverse from 0 to k ; Driver Code
using System ; class GFG { static int nCr ( int n , int r ) { int res = 1 ; if ( r > n - r ) r = n - r ; for ( int i = 0 ; i < r ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static int solve ( int n , int m , int k ) { int sum = 0 ; for ( int i = 0 ; i <= k ; i ++ ) sum += nCr ( n , i ) * nCr ( m , k - i ) ; return sum ; } public static void Main ( String [ ] args ) { int n = 3 , m = 2 , k = 2 ; Console . Write ( solve ( n , m , k ) ) ; } }
Fast Exponention using Bit Manipulation | C # program to implement the above approach ; Function to return a ^ n ; Stores readonly answer ; Check if current LSB is set ; Right shift ; Driver Code
using System ; class GFG { static int powerOptimised ( int a , int n ) { int ans = 1 ; while ( n > 0 ) { int last_bit = ( n & 1 ) ; if ( last_bit > 0 ) { ans = ans * a ; } a = a * a ; n = n >> 1 ; } return ans ; } public static void Main ( String [ ] args ) { int a = 3 , n = 5 ; Console . Write ( powerOptimised ( a , n ) ) ; } }
Find M such that GCD of M and given number N is maximum | C # program for the above approach ; Function to find the integer M such that gcd ( N , M ) is maximum ; Initialize a variable ; Find all the divisors of N and return the maximum divisor ; Check if i is divisible by N ; Update max_gcd ; Return the maximum value ; Driver Code ; Given Number ; Function Call
using System ; class GFG { static int findMaximumGcd ( int n ) { int max_gcd = 1 ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i > max_gcd ) max_gcd = i ; if ( ( n / i != i ) && ( n / i != n ) && ( ( n / i ) > max_gcd ) ) max_gcd = n / i ; } } return max_gcd ; } public static void Main ( String [ ] args ) { int N = 10 ; Console . Write ( findMaximumGcd ( N ) ) ; } }
First element of every K sets having consecutive elements with exactly K prime factors less than N | C # program for the above approach ; For storing smallest prime factor ; Function consmallest prime factor array ; Mark smallest prime factor for every number to be itself . ; Separately mark spf for every even number as 2 ; Check if i is prime ; Mark SPF for all numbers divisible by i ; Mark spf [ j ] if it is not previously marked ; Function for counts total number of prime factors ; Function to print elements of sets of K consecutive elements having K prime factors ; To store the result ; Count number of prime factors of number ; If number has exactly K factors push in result [ ] ; Iterate till we get K consecutive elements in result [ ] ; Count sequence until K ; Print the element if count >= K ; Driver code ; To construct spf [ ] ; Given N and K ; Function call
using System ; using System . Collections . Generic ; class GFG { static readonly int x = 2000021 ; static int [ ] v = new int [ x ] ; static void sieve ( ) { v [ 1 ] = 1 ; for ( int i = 2 ; i < x ; i ++ ) v [ i ] = i ; for ( int i = 4 ; i < x ; i += 2 ) v [ i ] = 2 ; for ( int i = 3 ; i * i < x ; i ++ ) { if ( v [ i ] == i ) { for ( int j = i * i ; j < x ; j += i ) { if ( v [ j ] == j ) { v [ j ] = i ; } } } } } static int prime_factors ( int n ) { HashSet < int > s = new HashSet < int > ( ) ; while ( n != 1 ) { s . Add ( v [ n ] ) ; n = n / v [ n ] ; } return s . Count ; } static void distinctPrimes ( int m , int k ) { List < int > result = new List < int > ( ) ; for ( int i = 14 ; i < m + k ; i ++ ) { long count = prime_factors ( i ) ; if ( count == k ) { result . Add ( i ) ; } } int p = result . Count ; for ( int index = 0 ; index < p - 1 ; index ++ ) { long element = result [ index ] ; int count = 1 , z = index ; while ( z < p - 1 && count <= k && result [ z ] + 1 == result [ z + 1 ] ) { count ++ ; z ++ ; } if ( count >= k ) Console . Write ( element + " ▁ " ) ; } } public static void Main ( String [ ] args ) { sieve ( ) ; int N = 1000 , K = 3 ; distinctPrimes ( N , K ) ; } }
Product of Complex Numbers using three Multiplication Operation | C # program for the above approach ; Function to multiply Complex Numbers with just three multiplications ; Find value of prod1 , prod2 and prod3 ; Real Part ; Imaginary Part ; Print the result ; Driver Code ; Given four Numbers ; Function Call
using System ; class GFG { static void print_product ( int a , int b , int c , int d ) { int prod1 = a * c ; int prod2 = b * d ; int prod3 = ( a + b ) * ( c + d ) ; int real = prod1 - prod2 ; int imag = prod3 - ( prod1 + prod2 ) ; Console . Write ( real + " ▁ + ▁ " + imag + " i " ) ; } public static void Main ( ) { int a , b , c , d ; a = 2 ; b = 3 ; c = 4 ; d = 5 ; print_product ( a , b , c , d ) ; } }
Insolite Numbers | C # implementation for the above approach ; Function to check if a number is an Insolite numbers ; To store sum of squares of digits ; To store product of squares of digits ; extracting digit ; Driver Code ; Function Call
using System ; class GFG { static bool isInsolite ( int n ) { int N = n ; int sum = 0 ; int product = 1 ; while ( n != 0 ) { int r = n % 10 ; sum = sum + r * r ; product = product * r * r ; n = n / 10 ; } return ( N % sum == 0 ) && ( N % product == 0 ) ; } public static void Main ( ) { int N = 111 ; if ( isInsolite ( N ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Superabundant Numbers | C # implementation to check if a number is Superabundant ; Function to calculate the sum of all divisors of a given number ; Sum of divisors ; Find all divisors which divides ' num ' ; If ' i ' is divisor of ' n ' ; If both divisors are same then add it once else add both ; Add 1 and n to result as above loop considers proper divisors greater than 1. ; Function to check if N is a superabundant number ; To check all numbers from 1 to N ; Driver code
using System ; class GFG { static int sigma ( int n ) { if ( n == 1 ) return 1 ; int result = 0 ; for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( i == ( n / i ) ) result += i ; else result += ( i + n / i ) ; } } return ( result + n + 1 ) ; } static bool isSuperabundant ( int N ) { for ( double i = 1 ; i < N ; i ++ ) { double x = sigma ( ( int ) ( i ) ) / i ; double y = sigma ( ( int ) ( N ) ) / ( N * 1.0 ) ; if ( x > y ) return false ; } return true ; } public static void Main ( String [ ] args ) { int N = 4 ; if ( isSuperabundant ( N ) ) Console . Write ( " Yes STRNEWLINE " ) ; else Console . Write ( " No STRNEWLINE " ) ; } }
D Numbers | C # implementation for the above approach ; Function to find the N - th icosikaipentagon number ; Number should be greater than 3 ; Check every k in range 2 to n - 1 ; Condition for D - Number ; Driver Code
using System ; class GFG { static bool isDNum ( int n ) { if ( n < 4 ) return false ; int numerator = 0 , hcf = 0 ; for ( int k = 2 ; k <= n ; k ++ ) { numerator = ( int ) ( Math . Pow ( k , n - 2 ) - k ) ; hcf = __gcd ( n , k ) ; } if ( hcf == 1 && ( numerator % n ) != 0 ) return false ; return true ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void Main ( String [ ] args ) { int n = 15 ; bool a = isDNum ( n ) ; if ( a ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Ruth | C # implementation of the above approach ; Function to find prime divisors of all numbers from 1 to N ; if the number is prime ; add this prime to all it 's multiples ; Function to check Ruth - Aaron number ; Driver code
using System ; class GFG { static int Sum ( int N ) { int [ ] SumOfPrimeDivisors = new int [ N + 1 ] ; for ( int i = 2 ; i <= N ; ++ i ) { if ( SumOfPrimeDivisors [ i ] == 1 ) { for ( int j = i ; j <= N ; j += i ) { SumOfPrimeDivisors [ j ] += i ; } } } return SumOfPrimeDivisors [ N ] ; } static bool RuthAaronNumber ( int n ) { if ( Sum ( n ) == Sum ( n + 1 ) ) return true ; else return false ; } public static void Main ( ) { int N = 714 ; if ( RuthAaronNumber ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Maximize sum of absolute difference between adjacent elements in Array with sum K | C # program to maximize the sum of absolute differences between adjacent elements ; Function for maximising the sum ; Difference is 0 when only one element is present in array ; Difference is K when two elements are present in array ; Otherwise ; Driver code
using System ; class GFG { static int maxAdjacentDifference ( int N , int K ) { if ( N == 1 ) { return 0 ; } if ( N == 2 ) { return K ; } return 2 * K ; } public static void Main ( String [ ] args ) { int N = 6 ; int K = 11 ; Console . Write ( maxAdjacentDifference ( N , K ) ) ; } }
Sum of all divisors from 1 to N | Set 2 | C # program for the above approach ; Functions returns sum of numbers from 1 to n ; Functions returns sum of numbers from a + 1 to b ; Function returns total sum of divisors ; Stores total sum ; Finding numbers and its occurence ; Sum of product of each number and its occurence ; Driver code
using System ; class GFG { static readonly int mod = 1000000007 ; public static int linearSum ( int n ) { return ( n * ( n + 1 ) / 2 ) % mod ; } public static int rangeSum ( int b , int a ) { return ( linearSum ( b ) - linearSum ( a ) ) % mod ; } public static int totalSum ( int n ) { int result = 0 ; int i = 1 ; while ( true ) { result += rangeSum ( n / i , n / ( i + 1 ) ) * ( i % mod ) % mod ; result %= mod ; if ( i == n ) break ; i = n / ( n / ( i + 1 ) ) ; } return result ; } public static void Main ( String [ ] args ) { int N = 4 ; Console . WriteLine ( totalSum ( N ) ) ; N = 12 ; Console . WriteLine ( totalSum ( N ) ) ; } }
Nontrivial undulant Numbers | C # implementation to check if N is a Nontrivial undulant number ; Function to check if a string is double string or not ; a and b should not be equal ; Condition to check if length is odd make length even ; First half of s ; Second half of s ; Double string if first and last half are equal ; Function to check if N is an Nontrivial undulant number ; Driver code
using System ; class GFG { static bool isDouble ( int num ) { String s = num . ToString ( ) ; int l = s . Length ; if ( s [ 0 ] == s [ 1 ] ) return false ; if ( l % 2 == 1 ) { s = s + s [ 1 ] ; l ++ ; } String s1 = s . Substring ( 0 , l / 2 ) ; String s2 = s . Substring ( l / 2 ) ; return s1 . Equals ( s2 ) ; } static bool isNontrivialUndulant ( int N ) { return N > 100 && isDouble ( N ) ; } public static void Main ( String [ ] args ) { int n = 121 ; if ( isNontrivialUndulant ( n ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Megagon number | C # program for the above approach ; Function to find the nth Megagon Number ; Driver code
using System ; class GFG { static int MegagonNum ( int n ) { return ( 999998 * n * n - 999996 * n ) / 2 ; } public static void Main ( String [ ] args ) { int n = 3 ; Console . Write ( MegagonNum ( n ) ) ; } }