codeparrot/xlcost-text-to-code huggingface dataset:
Find the sum of the first Nth Centered Hexadecagonal Number | C # program to find the sum of the first N centred hexadecagonal numbers ; Centered_Hexadecagonal number function ; Formula to calculate nth Centered_Hexadecagonal number & return it into main function . ; Function to find the sum of the first N centered hexadecagonal number ; Variable to store the sum ; Loop to iterate through the first N numbers ; Finding the sum ; Driver Code ; Display first Nth Centered_Hexadecagonal number
using System ; class GFG { public static int Centered_Hexadecagonal_num ( int n ) { return ( 8 * n * n - 8 * n + 1 ) ; } public static int sum_Centered_Hexadecagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += Centered_Hexadecagonal_num ( i ) ; } return summ ; } public static void Main ( ) { int n = 5 ; Console . Write ( sum_Centered_Hexadecagonal_num ( n ) ) ; } }
Find the sum of the first N Centered heptagonal number | C # program to find the sum of the first N centered heptagonal numbers ; Function to find the N - th centered heptagonal number ; Formula to calculate nth centered heptagonal number ; Function to find the sum of the first N centered heptagonal numbers ; Variable to store the sum ; Iterating through the range 1 to N ; Driver Code
using System ; class GFG { public static int center_heptagonal_num ( int n ) { return ( 7 * n * n - 7 * n + 2 ) / 2 ; } public static int sum_center_heptagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += center_heptagonal_num ( i ) ; } return summ ; } public static void Main ( ) { int n = 5 ; Console . Write ( sum_center_heptagonal_num ( n ) ) ; } }
Find the sum of the first N Centered Dodecagonal Number | C # program to find the sum of the first N centred dodecagonal number ; Function to find the N - th centered dodecagonal number ; Formula to calculate nth Centered_Dodecagonal number ; Function to find the sum of the first N Centered_Dodecagonal number ; Variable to store the sum ; Iterating from 1 to N ; Finding the sum ; Driver code
using System ; class GFG { static int Centered_Dodecagonal_num ( int n ) { return 6 * n * ( n - 1 ) + 1 ; } static int sum_Centered_Dodecagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += Centered_Dodecagonal_num ( i ) ; } return summ ; } public static void Main ( ) { int n = 5 ; Console . Write ( sum_Centered_Dodecagonal_num ( n ) ) ; } }
Find the sum of the first N Centered Octagonal Number | C # program to find the sum of the first N centered octagonal number ; Function to find N - th centered octagonal number ; Formula to calculate nth centered octagonal number ; Function to find the sum of the first N centered octagonal numbers ; Variable to store the sum ; Iterating through the first N numbers ; Driver code
using System ; class GFG { static int center_Octagonal_num ( int n ) { return ( 4 * n * n - 4 * n + 1 ) ; } static int sum_center_Octagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += center_Octagonal_num ( i ) ; } return summ ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( sum_center_Octagonal_num ( n ) ) ; } }
Find the sum of the first N Centered Decagonal Numbers | C # program to find the sum of the first N centred decagonal number ; Function to find the N - th centred decagonal number ; Formula to calculate nth centered_decagonal number & return it into main function . ; Function to find the sum of the first N centered decagonal numbers ; Variable to store the sum ; Iterating through the range ; Driver code ; Display first Nth centered_decagonal number
using System ; class GFG { static int Centered_decagonal_num ( int n ) { return ( 5 * n * n - 5 * n + 1 ) ; } static int sum_Centered_decagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += Centered_decagonal_num ( i ) ; } return summ ; } public static void Main ( String [ ] args ) { int n = 5 ; Console . WriteLine ( sum_Centered_decagonal_num ( n ) ) ; } }
Find the sum of the first N Centered Octadecagonal Numbers | C # program to find the sum of the first N centered octadecagonal numbers ; Function to find the N - th centered octadecagonal number ; Formula to calculate nth centered octadecagonal number ; Function to find the sum of the first N centered octadecagonal numbers ; Variable to store the sum ; Iterating through the range 1 to N ; Driver Code
using System ; class GFG { static int center_octadecagon_num ( int n ) { return ( 9 * n * n - 9 * n + 1 ) ; } static int sum_center_octadecagon_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += center_octadecagon_num ( i ) ; } return summ ; } public static void Main ( String [ ] args ) { int n = 3 ; Console . WriteLine ( sum_center_octadecagon_num ( n ) ) ; } }
Find the sum of the first Nth Centered Pentadecagonal Number | C # program to find the sum of the first N centered pentadecagonal number ; Function to find the centered pentadecagonal number ; Formula to calculate N - th centered pentadecagonal number ; Function to find the sum of the first N centered pentadecagonal numbers ; Variable to store the sum ; Driver Code
using System ; class GFG { static int Centered_Pentadecagonal_num ( int n ) { return ( 15 * n * n - 15 * n + 2 ) / 2 ; } static int sum_Centered_Pentadecagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += Centered_Pentadecagonal_num ( i ) ; } return summ ; } public static void Main ( String [ ] args ) { int n = 5 ; Console . WriteLine ( sum_Centered_Pentadecagonal_num ( n ) ) ; } }
Program to check if N is a Octagonal Number | C # program for the above approach ; Function to check if N is a octagonal number ; Condition to check if the number is a octagonal number ; Driver code ; Given number ; Function call
using System ; class GFG { public static bool isoctagonal ( int N ) { double n = ( 2 + Math . Sqrt ( 12 * N + 4 ) ) / 6 ; return ( n - ( int ) n ) == 0 ; } public static void Main ( String [ ] args ) { int N = 8 ; if ( isoctagonal ( N ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Program to check if N is a Pentadecagonal Number | C # program for the above approach ; Function to check if N is a pentadecagon number ; Condition to check if the number is a pentadecagon number ; Driver code ; Given Number ; Function call
using System ; class GFG { public static bool isPentadecagon ( int N ) { double n = ( 11 + Math . Sqrt ( 104 * N + 121 ) ) / 26 ; return ( n - ( int ) n ) == 0 ; } public static void Main ( String [ ] args ) { int N = 15 ; if ( isPentadecagon ( N ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Program to check if N is a Tetradecagonal Number | C # program for the above approach ; Function to check if N is a tetradecagonal number ; Condition to check if the number is a tetradecagonal number ; Driver Code ; Given number ; Function call
using System ; class GFG { public static bool istetradecagonal ( int N ) { double n = ( 10 + Math . Sqrt ( 96 * N + 100 ) ) / 24 ; return ( n - ( int ) n ) == 0 ; } static public void Main ( ) { int N = 11 ; if ( istetradecagonal ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Find the sum of the first Nth Icosagonal Numbers | C # program to find the sum of the first N icosagonal number ; Function to calculate the N - th icosagonal number ; Formula to calculate nth icosagonal number & return it ; Function to find the sum of the first N icosagonal numbers ; Variable to store the sum ; Loop to iterate through the first N values and find the sum of first N icosagonal numbers ; Function to get the Icosagonal_num ; Driver code ; Display the sum of first N icosagonal number
using System ; class GFG { public static int Icosagonal_num ( int n ) { return ( 18 * n * n - 16 * n ) / 2 ; } public static int sum_Icosagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { summ += Icosagonal_num ( i ) ; } return summ ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( sum_Icosagonal_num ( n ) ) ; } }
Find the sum of the first N Centered Pentagonal Number | C # program to find the sum of the first N centered pentagonal numbers ; Function to find the Centered_Pentagonal number ; Formula to calculate nth Centered_Pentagonal number & return it into main function . ; Function to find the sum of the first N Centered_Pentagonal numbers ; To get the sum ; Iterating through the range 1 to N ; Driver code ; Display first Nth Centered_Pentagonal number
using System ; class GFG { static int Centered_Pentagonal_num ( int n ) { return ( 5 * n * n - 5 * n + 2 ) / 2 ; } static int sum_Centered_Pentagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += Centered_Pentagonal_num ( i ) ; } return summ ; } public static void Main ( String [ ] args ) { int n = 5 ; Console . Write ( ( sum_Centered_Pentagonal_num ( n ) ) ) ; } }
Find the sum of the first Nth Centered Tridecagonal Numbers | C # program to find the sum of the first Nth centered tridecagonal number ; Function to calculate the N - th centered tridecagonal number ; Formula to calculate Nth centered tridecagonal number & return it ; Function to find the sum of the first N centered tridecagonal numbers ; Variable to store the sum ; Loop to iterate and find the sum of first N centered tridecagonal numbers ; Driver code
using System ; class GFG { public static int Centered_tridecagonal_num ( int n ) { return ( 13 * n * ( n - 1 ) + 2 ) / 2 ; } public static int sum_Centered_tridecagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { summ += Centered_tridecagonal_num ( i ) ; } return summ ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( sum_Centered_tridecagonal_num ( n ) ) ; } }
Program to check if N is a Concentric Hexagonal Number | C # program to check if N is a concentric hexagonal number ; Function to check if the number is a concentric hexagonal number ; Condition to check if the number is a concentric hexagonal number ; Driver Code ; Function call
using System ; class GFG { static bool isConcentrichexagonal ( int N ) { float n = ( float ) Math . Sqrt ( ( 2 * N ) / 3 ) ; return ( n - ( int ) n ) == 0 ; } public static void Main ( ) { int N = 6 ; if ( isConcentrichexagonal ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Count Sexy Prime Pairs in the given array | C # program to count Sexy Prime pairs in array ; To store check the prime number ; A utility function that find the Prime Numbers till N ; Resize the Prime Number ; Loop till Math . Sqrt ( N ) to find prime numbers and make their multiple false in the bool array Prime ; Function that returns the count of SPP ( Sexy Prime Pair ) Pairs ; Find the maximum element in the given array [ ] arr ; Function to calculate the prime numbers till N ; To store the count of pairs ; To store the frequency of element in the array [ ] arr ; Sort before traversing the array ; Traverse the array and find the pairs with SPP ( Sexy Prime Pair ) s ; If current element is Prime , then check for ( current element + 6 ) ; Return the count of pairs ; Driver code ; Function call to find SPP ( Sexy Prime Pair ) s pair
using System ; using System . Linq ; class GFG { static bool [ ] Prime ; static void computePrime ( int N ) { Prime = new bool [ N + 1 ] ; for ( int i = 0 ; i <= N ; i ++ ) { Prime [ i ] = true ; } Prime [ 0 ] = Prime [ 1 ] = false ; for ( int i = 2 ; i * i <= N ; i ++ ) { if ( Prime [ i ] ) { for ( int j = i * i ; j < N ; j += i ) { Prime [ j ] = false ; } } } } static int countSexyPairs ( int [ ] arr , int n ) { int maxE = arr . Max ( ) ; computePrime ( maxE ) ; int count = 0 ; int [ ] freq = new int [ maxE + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; } Array . Sort ( arr ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( Prime [ arr [ i ] ] ) { if ( arr [ i ] + 6 < freq . Length && freq [ arr [ i ] + 6 ] > 0 && Prime [ arr [ i ] + 6 ] ) { count ++ ; } } } return count ; } public static void Main ( String [ ] args ) { int [ ] arr = { 6 , 7 , 5 , 11 , 13 } ; int n = arr . Length ; Console . Write ( countSexyPairs ( arr , n ) ) ; } }
Count of ways to write N as a sum of three numbers | C # program to count the total number of ways to write N as a sum of three numbers ; Function to find the number of ways ; Check if number is less than 2 ; Calculate the sum ; Driver code
using System ; class GFG { static void countWays ( int n ) { if ( n <= 2 ) { Console . WriteLine ( " - 1" ) ; } else { int ans = ( n - 1 ) * ( n - 2 ) / 2 ; Console . WriteLine ( ans ) ; } } static void Main ( ) { int N = 5 ; countWays ( N ) ; } }
Logarithm tricks for Competitive Programming | C # implementation to check that a integer is a power of Two ; Function to check if the number is a power of two ; Driver Code
using System ; class GFG { public static bool isPowerOfTwo ( int n ) { return ( Math . Ceiling ( Math . Log ( n ) / Math . Log ( 2 ) ) == Math . Floor ( Math . Log ( n ) / Math . Log ( 2 ) ) ) ; } public static void Main ( String [ ] args ) { int N = 8 ; if ( isPowerOfTwo ( N ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Count of pairs having bit size at most X and Bitwise OR equal to X | C # implementation to count number of possible pairs of ( a , b ) such that their Bitwise OR gives the value X ; Function to count the pairs ; Initializing answer with 1 ; Iterating through bits of x ; Check if bit is 1 ; Multiplying ans by 3 if bit is 1 ; Driver code
using System ; class GFG { static int count_pairs ( int x ) { int ans = 1 ; while ( x > 0 ) { if ( x % 2 == 1 ) ans = ans * 3 ; x = x / 2 ; } return ans ; } public static void Main ( String [ ] args ) { int X = 6 ; Console . Write ( count_pairs ( X ) + " STRNEWLINE " ) ; } }
Find the Kth number which is not divisible by N | C # implementation for above approach ; Function to find the Kth not divisible by N ; Lowest possible value ; Highest possible value ; To store the Kth non divisible number of N ; Using binary search ; Calculating mid value ; Sol would have the value by subtracting all multiples of n till mid ; Check if sol is greater than k ; H should be reduced to find minimum possible value ; Check if sol is less than k then L will be mid + 1 ; Check if sol is equal to k ; ans will be mid ; H would be reduced to find any more possible value ; Print the answer ; Driver code ; Function Call
using System ; class GFG { static void kthNonDivisible ( int N , int K ) { int L = 1 ; int H = Int32 . MaxValue ; int ans = 0 ; while ( L <= H ) { int mid = ( L + H ) / 2 ; int sol = mid - mid / N ; if ( sol > K ) { H = mid - 1 ; } else if ( sol < K ) { L = mid + 1 ; } else { ans = mid ; H = mid - 1 ; } } Console . Write ( ans ) ; } static void Main ( ) { int N = 3 ; int K = 7 ; kthNonDivisible ( N , K ) ; } }
Print any pair of integers with sum of GCD and LCM equals to N | C # implementation to print any pair of integers whose summation of GCD and LCM is equal to integer N ; Function to print the required pair ; Print the pair ; Driver code
using System ; public class GFG { static void printPair ( int n ) { Console . Write ( 1 + " ▁ " + ( n - 1 ) ) ; } public static void Main ( String [ ] args ) { int n = 14 ; printPair ( n ) ; } }
Find the length of largest subarray in which all elements are Autobiographical Numbers | C # program to find the length of the largest subarray whose every element is an autobiographical number ; Function to check number is autobiographical ; Convert integer to string ; Iterate for every digit to check for their total count ; Check occurrence of every number and count them ; Check if any position mismatches with total count them return with false else continue with loop ; Function to return the length of the largest subarray whose every element is a autobiographical number ; Utility function which checks every element of array for autobiographical number ; Check if element arr [ i ] is an autobiographical number ; Increment the current length ; Update max_length value ; Return the final result ; Driver code
using System ; class GFG { static bool isAutoBiographyNum ( int number ) { int count = 0 , position , size , digit ; string NUM ; NUM = number . ToString ( ) ; size = NUM . Length ; for ( int i = 0 ; i < size ; i ++ ) { position = NUM [ i ] - '0' ; count = 0 ; for ( int j = 0 ; j < size ; j ++ ) { digit = NUM [ j ] - '0' ; if ( digit == i ) count ++ ; } if ( position != count ) return false ; } return true ; } static int checkArray ( int [ ] arr , int n ) { int current_length = 0 ; int max_length = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isAutoBiographyNum ( arr [ i ] ) == true ) { current_length ++ ; } else { current_length = 0 ; } max_length = Math . Max ( max_length , current_length ) ; } return max_length ; } public static void Main ( string [ ] args ) { int [ ] arr = { 21200 , 1 , 1303 , 1210 , 2020 } ; int n = arr . Length ; Console . WriteLine ( checkArray ( arr , n ) ) ; } }
Print the nodes of the Binary Tree whose height is a Prime number | C # implementation of nodes at prime height in the given tree ; To store Prime Numbers ; To store height of each node ; Function to find the prime numbers till 10 ^ 5 ; Traverse all multiple of i and make it false ; Function to perform dfs ; Store the height of node ; Function to find the nodes at prime height ; To precompute prime number till 10 ^ 5 ; Check if height [ node ] is prime ; Driver code ; Number of nodes ; Edges of the tree
using System ; using System . Collections . Generic ; class GFG { static readonly int MAX = 100000 ; static List < int > [ ] graph = new List < int > [ MAX + 1 ] ; static bool [ ] Prime = new bool [ MAX + 1 ] ; static int [ ] height = new int [ MAX + 1 ] ; static void SieveOfEratosthenes ( ) { int i , j ; Prime [ 0 ] = Prime [ 1 ] = false ; for ( i = 2 ; i * i <= MAX ; i ++ ) { if ( Prime [ i ] ) { for ( j = 2 * i ; j < MAX ; j += i ) { Prime [ j ] = false ; } } } } static void dfs ( int node , int parent , int h ) { height [ node ] = h ; foreach ( int to in graph [ node ] ) { if ( to == parent ) continue ; dfs ( to , node , h + 1 ) ; } } static void primeHeightNode ( int N ) { SieveOfEratosthenes ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { if ( Prime [ height [ i ] ] ) { Console . Write ( i + " ▁ " ) ; } } } public static void Main ( String [ ] args ) { int N = 5 ; for ( int i = 0 ; i < Prime . Length ; i ++ ) Prime [ i ] = true ; for ( int i = 0 ; i < graph . Length ; i ++ ) graph [ i ] = new List < int > ( ) ; graph [ 1 ] . Add ( 2 ) ; graph [ 1 ] . Add ( 3 ) ; graph [ 2 ] . Add ( 4 ) ; graph [ 2 ] . Add ( 5 ) ; dfs ( 1 , 1 , 0 ) ; primeHeightNode ( N ) ; } }
Find Prime Adam integers in the given range [ L , R ] | C # program to find all prime adam numbers in the given range ; Reversing a number by taking remainder at a time ; Function to check if a number is a prime or not ; Iterating till the number ; Checking for factors ; Returning 1 if the there are no factors of the number other than 1 or itself ; Function to check whether a number is an adam number or not ; Reversing given number ; Squaring given number ; Squaring reversed number ; Reversing the square of the reversed number ; Checking if the square of the number and the square of its reverse are equal or not ; Function to find all the prime adam numbers in the given range ; If the first number is greater than the second number , print invalid ; Iterating through all the numbers in the given range ; Checking for prime number ; Checking for Adam number ; Driver code
using System ; class GFG { public static int reverse ( int a ) { int rev = 0 ; while ( a != 0 ) { int r = a % 10 ; rev = rev * 10 + r ; a = a / 10 ; } return ( rev ) ; } public static int prime ( int a ) { int k = 0 ; for ( int i = 2 ; i < a ; i ++ ) { if ( a % i == 0 ) { k = 1 ; break ; } } if ( k == 1 ) { return ( 0 ) ; } else { return ( 1 ) ; } } public static int adam ( int a ) { int r1 = reverse ( a ) ; int s1 = a * a ; int s2 = r1 * r1 ; int r2 = reverse ( s2 ) ; if ( s1 == r2 ) { return ( 1 ) ; } else { return ( 0 ) ; } } public static void find ( int m , int n ) { if ( m > n ) { Console . WriteLine ( " INVALID ▁ INPUT " ) ; } else { for ( int i = m ; i <= n ; i ++ ) { int l = prime ( i ) ; int k = adam ( i ) ; if ( ( l == 1 ) && ( k == 1 ) ) { Console . Write ( i + " TABSYMBOL " ) ; } } } } public static void Main ( String [ ] args ) { int L = 5 , R = 100 ; find ( L , R ) ; } }
Determine whether the given integer N is a Peculiar Number or not | C # implementation to check if the number is peculiar ; Function to find sum of digits of a number ; Function to check if the number is peculiar ; Store a duplicate of n ; Driver code
using System ; class GFG { static int sumDig ( int n ) { int s = 0 ; while ( n != 0 ) { s = s + ( n % 10 ) ; n = n / 10 ; } return s ; } static bool Pec ( int n ) { int dup = n ; int dig = sumDig ( n ) ; if ( dig * 3 == dup ) return true ; else return false ; } public static void Main ( ) { int n = 36 ; if ( Pec ( n ) == true ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Find N numbers such that a number and its reverse are divisible by sum of its digits | C # program to print the first N numbers such that every number and the reverse of the number is divisible by its sum of digits ; Function to calculate the sum of digits ; Loop to iterate through every digit of the number ; Returning the sum of digits ; Function to calculate the reverse of a number ; Loop to calculate the reverse of the number ; Return the reverse of the number ; Function to print the first N numbers such that every number and the reverse of the number is divisible by its sum of digits ; Loop to continuously check and generate number until there are n outputs ; Variable to hold the sum of the digit of the number ; Computing the reverse of the number ; Checking if the condition satisfies . Increment the count and print the number if it satisfies . ; Driver code
using System ; class GFG { static int digit_sum ( int n ) { int sum = 0 , m ; while ( n > 0 ) { m = n % 10 ; sum = sum + m ; n = n / 10 ; } return ( sum ) ; } static int reverse ( int n ) { int r = 0 ; while ( n != 0 ) { r = r * 10 ; r = r + n % 10 ; n = n / 10 ; } return ( r ) ; } static void operation ( int n ) { int i = 1 , a , count = 0 , r ; while ( count < n ) { a = digit_sum ( i ) ; r = reverse ( i ) ; if ( i % a == 0 && r % a == 0 ) { Console . Write ( i + " ▁ " ) ; count ++ ; i ++ ; } else i ++ ; } } public static void Main ( ) { int n = 10 ; operation ( n ) ; } }
Split N natural numbers into two sets having GCD of their sums greater than 1 | C # program to split N natural numbers into two sets having GCD of their sums greater than 1 ; Function to create and print the two sets ; No such split possible for N <= 2 ; Print the first set consisting of even elements ; Print the second set consisting of odd ones ; Driver Code
using System ; class GFG { static void createSets ( int N ) { if ( N <= 2 ) { Console . WriteLine ( " - 1" ) ; return ; } for ( int i = 2 ; i <= N ; i += 2 ) Console . Write ( i + " ▁ " ) ; Console . Write ( " STRNEWLINE " ) ; for ( int i = 1 ; i <= N ; i += 2 ) { Console . Write ( i + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int N = 6 ; createSets ( N ) ; } }