codeparrot/xlcost-text-to-code huggingface dataset:
Find prime factors of Array elements whose sum of exponents is divisible by K | C # program for the above approach ; To store the smallest prime factor till 10 ^ 5 ; Function to compute smallest prime factor array ; Initialize the spf array first element ; Marking smallest prime factor for every number to be itself ; Separately marking smallest prime factor for every even number as 2 ; Checking if i is prime ; Marking SPF for all numbers divisible by i ; Marking spf [ j ] if it is not previously marked ; Function that finds minimum operation ; Create a spf [ ] array ; Map created to store the unique prime numbers ; To store the result ; To store every unique prime number ; Erase 1 as a key because it is not a prime number ; First prime number ; Frequency is divisible by K then insert primeNum in the result [ ] ; Print the elements if it exists ; Driver code ; Given array [ ] arr ; Given K ; Function call
using System ; using System . Collections . Generic ; class GFG { static int [ ] spf = new int [ 10001 ] ; static void spf_array ( int [ ] spf ) { spf [ 1 ] = 1 ; for ( int i = 2 ; i < 1000 ; i ++ ) spf [ i ] = i ; for ( int i = 4 ; i < 1000 ; i += 2 ) spf [ i ] = 2 ; for ( int i = 3 ; i * i < 1000 ; i ++ ) { if ( spf [ i ] == i ) { for ( int j = i * i ; j < 1000 ; j += i ) if ( spf [ j ] == j ) spf [ j ] = i ; } } } static void frequent_prime ( int [ ] arr , int N , int K ) { spf_array ( spf ) ; SortedDictionary < int , int > Hmap = new SortedDictionary < int , int > ( ) ; List < int > result = new List < int > ( ) ; int i = 0 ; for ( i = 0 ; i < N ; i ++ ) { int x = arr [ i ] ; while ( x != 1 ) { if ( Hmap . ContainsKey ( spf [ x ] ) ) Hmap [ spf [ x ] ] = spf [ x ] + 1 ; else Hmap . Add ( spf [ x ] , 1 ) ; x = x / spf [ x ] ; } } Hmap . Remove ( 1 ) ; foreach ( KeyValuePair < int , int > x in Hmap ) { int primeNum = x . Key ; int frequency = x . Value ; if ( frequency % K == 0 ) { result . Add ( primeNum ) ; } } if ( result . Count > 0 ) { foreach ( int it in result ) { Console . Write ( it + " ▁ " ) ; } } else { Console . Write ( " { } " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 4 , 6 } ; int K = 1 ; int N = arr . Length ; frequent_prime ( arr , N , K ) ; } }
Generate first K multiples of N using Bitwise operators | C # program to implement the above approach ; Function to print the first K multiples of N ; Print the value of N * i ; Iterate each bit of N and add Math . Pow ( 2 , pos ) , where pos is the index of each set bit ; Check if current bit at pos j is fixed or not ; For next set bit ; Driver Code
using System ; class GFG { static void Kmultiples ( int n , int k ) { int a = n ; for ( int i = 1 ; i <= k ; i ++ ) { Console . Write ( n + " ▁ * ▁ " + i + " ▁ = ▁ " + a + " STRNEWLINE " ) ; int j = 0 ; while ( n >= ( 1 << j ) ) { a += n & ( 1 << j ) ; j ++ ; } } } public static void Main ( String [ ] args ) { int N = 16 , K = 7 ; Kmultiples ( N , K ) ; } }
Least Square Regression Line | C # program to find the regression line ; Function to calculate b ; Sum of array x ; Sum of array y ; For sum of product of x and y ; Sum of square of x ; Function to find the least regression line ; Finding b ; Calculating a ; Printing regression line ; Driver code ; Statistical data
using System ; using System . Linq ; class GFG { private static double calculateB ( int [ ] x , int [ ] y ) { int n = x . Length ; int sx = x . Sum ( ) ; int sy = y . Sum ( ) ; int sxsy = 0 ; int sx2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sxsy += x [ i ] * y [ i ] ; sx2 += x [ i ] * x [ i ] ; } double b = ( double ) ( n * sxsy - sx * sy ) / ( n * sx2 - sx * sx ) ; return b ; } public static void leastRegLine ( int [ ] X , int [ ] Y ) { double b = calculateB ( X , Y ) ; int n = X . Length ; int meanX = X . Sum ( ) / n ; int meanY = Y . Sum ( ) / n ; double a = meanY - b * meanX ; Console . WriteLine ( " Regression ▁ line : " ) ; Console . Write ( " Y ▁ = ▁ " ) ; Console . Write ( " { 0 : F3 } " , a ) ; Console . Write ( " ▁ + ▁ " ) ; Console . Write ( " { 0 : F3 } " , b ) ; Console . Write ( " * X " ) ; } public static void Main ( String [ ] args ) { int [ ] X = { 95 , 85 , 80 , 70 , 60 } ; int [ ] Y = { 90 , 80 , 70 , 65 , 60 } ; leastRegLine ( X , Y ) ; } }
Count of repeating digits in a given Number | C # program for the above approach ; Function that returns the count of repeating digits of the given number ; Initialize a variable to store count of Repeating digits ; Initialize cnt array to store digit count ; Iterate through the digits of N ; Retrieve the last digit of N ; Increase the count of digit ; Remove the last digit of N ; Iterate through the cnt array ; If frequency of digit is greater than 1 ; Increment the count of Repeating digits ; Return count of repeating digit ; Driver Code ; Given array [ ] arr ; Function Call
using System ; class GFG { static int countRepeatingDigits ( int N ) { int res = 0 ; int [ ] cnt = new int [ 10 ] ; while ( N > 0 ) { int rem = N % 10 ; cnt [ rem ] ++ ; N = N / 10 ; } for ( int i = 0 ; i < 10 ; i ++ ) { if ( cnt [ i ] > 1 ) { res ++ ; } } return res ; } public static void Main ( String [ ] args ) { int N = 12 ; Console . WriteLine ( countRepeatingDigits ( N ) ) ; } }
Find temperature of missing days using given sum and average | C # program for the above approach ; Function for finding the temperature ; Store Day1 - Day2 in diff ; Remaining from s will be Day1 ; Print Day1 and Day2 ; Driver Code ; Functions
using System ; class GFG { static void findTemperature ( int x , int y , int s ) { double Day1 , Day2 ; double diff = ( x - y ) * 6 ; Day2 = ( diff + s ) / 2 ; Day1 = s - Day2 ; Console . Write ( " Day1 ▁ : ▁ " + Day1 + ' STRNEWLINE ' ) ; Console . WriteLine ( " Day2 ▁ : ▁ " + Day2 + ' STRNEWLINE ' ) ; } public static void Main ( string [ ] args ) { int x = 5 , y = 10 , s = 40 ; findTemperature ( x , y , s ) ; } }
Find two numbers whose sum is N and does not contain any digit as K | C # program for the above approach ; Function to find two numbers whose sum is N and do not contain any digit as k ; Check every number i and ( n - i ) ; Check if i and n - i doesn 't  contain k in them print i and n-i ; Check if flag is 0 then print - 1 ; Driver code ; Given N and K ; Function call
using System ; class GFG { static int freqCount ( String str , char k ) { int count = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == k ) count ++ ; } return count ; } static void findAandB ( int n , int k ) { int flag = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( freqCount ( i . ToString ( ) , ( char ) ( k + 48 ) ) == 0 && freqCount ( ( n - i ) . ToString ( ) , ( char ) ( k + 48 ) ) == 0 ) { Console . Write ( " ( " + i + " , ▁ " + ( n - i ) + " ) " ) ; flag = 1 ; break ; } } if ( flag == 0 ) Console . Write ( - 1 ) ; } public static void Main ( String [ ] args ) { int N = 100 ; int K = 0 ; findAandB ( N , K ) ; } }
Find the value of P and modular inverse of Q modulo 998244353 | C # implementation to find the value of P . Q - 1 mod 998244353 ; Function to find the value of P * Q ^ - 1 mod 998244353 ; Loop to find the value until the expo is not zero ; Multiply p with q if expo is odd ; Reduce the value of expo by 2 ; Driver code ; Function call
using System ; class GFG { static long calculate ( long p , long q ) { long mod = 998244353 , expo ; expo = mod - 2 ; while ( expo != 0 ) { if ( ( expo & 1 ) == 1 ) { p = ( p * q ) % mod ; } q = ( q * q ) % mod ; expo >>= 1 ; } return p ; } public static void Main ( string [ ] args ) { long p = 1 , q = 4 ; Console . WriteLine ( calculate ( p , q ) ) ; } }
Find two numbers with given sum and maximum possible LCM | C # program of the above approach ; Function that print two numbers with the sum X and maximum possible LCM ; Variables to store the result ; If X is odd ; If X is even ; If floor ( X / 2 ) is even ; If floor ( X / 2 ) is odd ; Print the result ; Driver code ; Given number ; Function call
using System ; class GFG { static void maxLCMWithGivenSum ( int X ) { int A , B ; if ( ( X & 1 ) == 1 ) { A = X / 2 ; B = X / 2 + 1 ; } else { if ( ( X / 2 ) % 2 == 0 ) { A = X / 2 - 1 ; B = X / 2 + 1 ; } else { A = X / 2 - 2 ; B = X / 2 + 2 ; } } Console . WriteLine ( A + " ▁ " + B ) ; } public static void Main ( String [ ] args ) { int X = 30 ; maxLCMWithGivenSum ( X ) ; } }
Length of longest subarray whose sum is not divisible by integer K | C # program to find the length of the longest subarray whose sum is not divisible by integer K ; Function to find the longest subarray with sum is not divisible by k ; left is the index of the leftmost element that is not divisible by k ; right is the index of the rightmost element that is not divisible by k ; sum of the array ; Find the element that is not multiple of k ; left = - 1 means we are finding the leftmost element that is not divisible by k ; Updating the rightmost element ; Update the sum of the array up to the index i ; Check if the sum of the array is not divisible by k , then return the size of array ; All elements of array are divisible by k , then no such subarray possible so return - 1 ; Length of prefix elements that can be removed ; Length of suffix elements that can be removed ; Return the length of subarray after removing the elements which have lesser number of elements ; Driver code
using System ; class GFG { static int MaxSubarrayLength ( int [ ] arr , int n , int k ) { int left = - 1 ; int right = 0 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] % k ) != 0 ) { if ( left == - 1 ) { left = i ; } right = i ; } sum += arr [ i ] ; } if ( ( sum % k ) != 0 ) { return n ; } else if ( left == - 1 ) { return - 1 ; } else { int prefix_length = left + 1 ; int suffix_length = n - right ; return n - Math . Min ( prefix_length , suffix_length ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 6 , 3 , 12 , 15 } ; int n = arr . Length ; int K = 3 ; Console . Write ( MaxSubarrayLength ( arr , n , K ) ) ; } }
Minimum steps to convert X to Y by repeated division and multiplication | C # implementation to find minimum steps to convert X to Y by repeated division and multiplication ; Check if X is greater than Y then swap the elements ; Check if X equals Y ; Driver code
using System ; class GFG { static int solve ( int X , int Y ) { if ( X > Y ) { int temp = X ; X = Y ; Y = temp ; } if ( X == Y ) Console . WriteLine ( 0 ) ; else if ( Y % X == 0 ) Console . WriteLine ( 1 ) ; else Console . WriteLine ( 2 ) ; return 0 ; } public static void Main ( String [ ] args ) { int X = 8 , Y = 13 ; solve ( X , Y ) ; } }
Count quadruplets ( A , B , C , D ) till N such that sum of square of A and B is equal to that of C and D | C # program for the above approach ; Function to count the quadruples ; Counter variable ; Map to store the sum of pair ( a ^ 2 + b ^ 2 ) ; Iterate till N ; Calculate a ^ 2 + b ^ 2 ; Increment the value in map ; Check if this sum was also in a ^ 2 + b ^ 2 ; Return the count ; Driver code ; Given N ; Function call
using System ; using System . Collections . Generic ; class GFG { static long countQuadraples ( long N ) { long cnt = 0 ; Dictionary < long , long > m = new Dictionary < long , long > ( ) ; for ( long a = 1 ; a <= N ; a ++ ) { for ( long b = 1 ; b <= N ; b ++ ) { long x = a * a + b * b ; if ( m . ContainsKey ( x ) ) m [ x ] = m [ x ] + 1 ; else m . Add ( x , 1 ) ; } } for ( long c = 1 ; c <= N ; c ++ ) { for ( long d = 1 ; d <= N ; d ++ ) { long x = c * c + d * d ; if ( m . ContainsKey ( x ) ) cnt += m [ x ] ; } } return cnt ; } public static void Main ( String [ ] args ) { long N = 2 ; Console . WriteLine ( countQuadraples ( N ) ) ; } }
Count of distinct index pair ( i , j ) such that element sum of First Array is greater | C # program for the above problem ; function to find the number of pairs satisfying the given cond . ; variables used for traversal ; count variable to store the count of possible pairs ; Nested loop to find out the possible pairs ; Check if the given condition is satisfied or not . If yes then increment the count . ; Return the count value ; Driver Code ; Size of the arrays ; Initialise the arrays ; function call that returns the count of possible pairs
using System ; class GFG { static int count_pairs ( int [ ] a , int [ ] b , int N ) { int i , j ; int count = 0 ; for ( i = 0 ; i < ( N - 1 ) ; i ++ ) { for ( j = ( i + 1 ) ; j < N ; j ++ ) { if ( ( a [ i ] + a [ j ] ) > ( b [ i ] + b [ j ] ) ) { count ++ ; } } } return count ; } public static void Main ( ) { int N = 5 ; int [ ] a = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; int [ ] b = new int [ ] { 2 , 5 , 6 , 1 , 9 } ; Console . Write ( count_pairs ( a , b , N ) ) ; } }
Count of distinct index pair ( i , j ) such that element sum of First Array is greater | C # program of the above approach ; Function to find the number of pairs . ; Array c [ ] where c [ i ] = a [ i ] - b [ i ] ; Sort the array c ; Initialise answer as 0 ; Iterate from index 0 to n - 1 ; If c [ i ] <= 0 then in the sorted array c [ i ] + c [ pos ] can never greater than 0 where pos < i ; Which is equivalent to c [ j ] >= - c [ i ] + 1 ; Add ( i - pos ) to answer ; Return the answer ; Driver Code ; Number of elements in a and b ; Array a ; Array b
using System ; class GFG { static int numberOfPairs ( int [ ] a , int [ ] b , int n ) { int [ ] c = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { c [ i ] = a [ i ] - b [ i ] ; } Array . Sort ( c ) ; int answer = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( c [ i ] <= 0 ) continue ; int pos = - 1 ; for ( int j = 0 ; j < n ; j ++ ) { if ( c [ i ] + c [ j ] > 0 ) { pos = j ; break ; } } answer += ( i - pos ) ; } return answer ; } static void Main ( ) { int n = 5 ; int [ ] a = { 1 , 2 , 3 , 4 , 5 } ; int [ ] b = { 2 , 5 , 6 , 1 , 9 } ; Console . WriteLine ( numberOfPairs ( a , b , n ) ) ; } }
Find K for every Array element such that at least K prefixes are â ‰¥ K | C # program for the above approach ; Function to find the K - value for every index in the array ; Multiset to store the array in the form of red - black tree ; Iterating over the array ; Inserting the current value in the multiset ; Condition to check if the smallest value in the set is less than it 's size ; Erase the smallest value ; h - index value will be the size of the multiset ; Driver code ; Array ; Size of the array ; Function call
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static void print_h_index ( int [ ] arr , int N ) { ArrayList ms = new ArrayList ( ) ; for ( int i = 0 ; i < N ; i ++ ) { ms . Add ( arr [ i ] ) ; int t = int . MaxValue ; foreach ( int x in ms ) { if ( x < t ) { t = x ; } } if ( t < ms . Count ) { ms . Remove ( t ) ; } Console . Write ( ms . Count + " ▁ " ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 9 , 10 , 7 , 5 , 0 , 10 , 2 , 0 } ; int N = arr . Length ; print_h_index ( arr , N ) ; } }
Non | C # program to find Non - repeating Primes ; Function to find count of prime ; Find maximum value in the array ; Create a boolean array " prime [ 0 . . n ] " . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; Remaining part of SIEVE ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Function to print Non - repeating primes ; Precompute primes using Sieve ; Create HashMap to store frequency of prime numbers ; Traverse through array elements and Count frequencies of all primes ; Traverse through map and print non repeating primes ; Driver code
using System ; using System . Collections ; using System . Linq ; using System . Collections . Generic ; class GFG { static List < bool > findPrimes ( int [ ] arr , int n ) { int max_val = arr . Max ( ) ; List < bool > prime = new List < bool > ( max_val + 1 ) ; for ( int i = 0 ; i < max_val + 1 ; i ++ ) prime . Add ( true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } return prime ; } static void nonRepeatingPrimes ( int [ ] arr , int n ) { List < bool > prime = findPrimes ( arr , n ) ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) if ( mp . ContainsKey ( arr [ i ] ) ) mp [ arr [ i ] ] ++ ; else mp . Add ( arr [ i ] , 1 ) ; } foreach ( KeyValuePair < int , int > entry in mp ) { if ( entry . Value == 1 ) Console . WriteLine ( entry . Key ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 2 , 3 , 4 , 6 , 7 , 9 , 7 , 23 , 21 , 3 } ; int n = arr . Length ; nonRepeatingPrimes ( arr , n ) ; } }
Prefix Product Array | C # program to generate Prefix Product Array ; Function to generate prefix product array ; Update the array with the product of prefixes ; Print the array ; Driver Code
using System ; class GFG { static int prefixProduct ( int [ ] a , int n ) { for ( int i = 1 ; i < n ; i ++ ) { a [ i ] = a [ i ] * a [ i - 1 ] ; } for ( int j = 0 ; j < n ; j ++ ) { Console . Write ( a [ j ] + " , ▁ " ) ; } return 0 ; } public static void Main ( string [ ] args ) { int [ ] arr = new int [ ] { 2 , 4 , 6 , 5 , 10 } ; int N = 5 ; prefixProduct ( arr , N ) ; } }
Count of ways to distribute N items among 3 people with one person receiving maximum | C # program to find the number of ways to distribute N item among three people such that one person always gets the maximum value ; Function to find the number of ways to distribute N items among 3 people ; No distribution possible ; Total number of ways to distribute N items among 3 people ; Store the number of distributions which are not possible ; Count possibilities of two persons receiving the maximum ; If N is divisible by 3 ; Return the final count of ways to distribute ; Driver Code
using System ; class GFG { static int countWays ( int N ) { if ( N < 4 ) return 0 ; int ans = ( ( N - 1 ) * ( N - 2 ) ) / 2 ; int s = 0 ; for ( int i = 2 ; i <= N - 3 ; i ++ ) { for ( int j = 1 ; j < i ; j ++ ) { if ( N == 2 * i + j ) s ++ ; } } if ( N % 3 == 0 ) s = 3 * s + 1 ; else s = 3 * s ; return ans - s ; } public static void Main ( ) { int N = 10 ; Console . Write ( countWays ( N ) ) ; } }
Magnanimous Numbers | C # implementation to check if a number is Magnanimous ; Function to check if n is prime ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to check if the number is Magnanimous or not ; Converting the number to string ; Finding length of string ; Number should not be of single digit ; Loop to find all left and right part of the string ; Driver code
using System ; class GFG { static bool isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static bool isMagnanimous ( int N ) { String s = N . ToString ( ) ; int l = s . Length ; if ( l < 2 ) return false ; for ( int i = 0 ; i < l - 1 ; i ++ ) { String left = s . Substring ( 0 , i + 1 ) ; String right = s . Substring ( i + 1 ) ; int x = int . Parse ( left ) ; int y = int . Parse ( right ) ; if ( ! isPrime ( x + y ) ) return false ; } return true ; } public static void Main ( String [ ] args ) { int N = 12 ; if ( isMagnanimous ( N ) ) Console . Write ( " Yes STRNEWLINE " ) ; else Console . Write ( " No STRNEWLINE " ) ; } }
Honaker Prime Number | C # program for above approach ; Function to precompute the position of every prime number using Sieve ; 0 and 1 are not prime numbers ; Variable to store the position ; Incrementing the position for every prime number ; Function to get sum of digits ; Function to check whether the given number is Honaker Prime number or not ; Driver code ; Precompute the prime numbers till 10 ^ 6 ; Given Number ; Function Call
using System ; class GFG { static readonly int limit = 10000000 ; static int [ ] position = new int [ limit + 1 ] ; static void sieve ( ) { position [ 0 ] = - 1 ; position [ 1 ] = - 1 ; int pos = 0 ; for ( int i = 2 ; i <= limit ; i ++ ) { if ( position [ i ] == 0 ) { position [ i ] = ++ pos ; for ( int j = i * 2 ; j <= limit ; j += i ) position [ j ] = - 1 ; } } } static int getSum ( int n ) { int sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = n / 10 ; } return sum ; } static bool isHonakerPrime ( int n ) { int pos = position [ n ] ; if ( pos == - 1 ) return false ; return getSum ( n ) == getSum ( pos ) ; } public static void Main ( String [ ] args ) { sieve ( ) ; int N = 121 ; if ( isHonakerPrime ( N ) ) Console . Write ( " Yes STRNEWLINE " ) ; else Console . Write ( " No STRNEWLINE " ) ; } }
Check if Matrix sum is prime or not | C # implementation to check if the sum of matrix is prime or not ; Function to check whether a number is prime or not ; Corner case ; Check from 2 to n - 1 ; Function for to find the sum of the given matrix ; Driver Code
using System ; class GFG { static int N = 4 , M = 5 ; static Boolean isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static int takeSum ( int [ ] [ ] a ) { int s = 0 ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) s += a [ i ] [ j ] ; return s ; } public static void Main ( String [ ] args ) { int [ ] [ ] a = new int [ ] [ ] { new int [ ] { 1 , 2 , 3 , 4 , 2 } , new int [ ] { 0 , 1 , 2 , 3 , 34 } , new int [ ] { 0 , 34 , 21 , 12 , 12 } , new int [ ] { 1 , 2 , 3 , 6 , 6 } } ; int sum = takeSum ( a ) ; if ( isPrime ( sum ) ) Console . Write ( " YES " + " STRNEWLINE " ) ; else Console . Write ( " NO " + " STRNEWLINE " ) ; } }
Sum of sum | C # program to implement the above approach ; Function to find the sum ; Calculate sum - series for every natural number and add them ; Driver code
using System ; class GFG { static long sumOfSumSeries ( int N ) { long sum = 0L ; for ( int i = 1 ; i <= N ; i ++ ) { sum = sum + ( i * ( i + 1 ) ) / 2 ; } return sum ; } public static void Main ( ) { int N = 5 ; Console . Write ( sumOfSumSeries ( N ) ) ; } }
Sum of sum | C # program to implement the above approach ; Function to find the sum ; Driver code
using System ; class GFG { static long sumOfSumSeries ( int n ) { return ( n * ( n + 1 ) * ( n + 2 ) ) / 6 ; } public static void Main ( String [ ] args ) { int N = 5 ; Console . Write ( sumOfSumSeries ( N ) ) ; } }
Tetradic Primes | C # implementation to print all Tetradic primes smaller than or equal to N . ; Function to check if the number N having all digits lies in the set ( 0 , 1 , 8 ) ; Function to check if the number N is palindrome ; Function to check if a number N is Tetradic ; Function to generate all primes and checking whether number is Tetradic or not ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Print all Tetradic prime numbers ; Checking whether the given number is prime Tetradic or not ; Driver code
using System ; class GFG { static bool isContaindigit ( int n ) { while ( n > 0 ) { if ( ! ( n % 10 == 0 n % 10 == 1 n % 10 == 8 ) ) return false ; n = n / 10 ; } return true ; } static bool ispalindrome ( int n ) { string temp = n . ToString ( ) ; int l = temp . Length ; for ( int i = 0 ; i < l / 2 ; i ++ ) { if ( temp [ i ] != temp [ l - i - 1 ] ) return false ; } return true ; } static bool isTetradic ( int n ) { if ( ispalindrome ( n ) && isContaindigit ( n ) ) return true ; return false ; } static void printTetradicPrimesLessThanN ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; Array . Fill ( prime , true ) ; int p = 2 ; while ( p * p <= n ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i < n + 1 ; i += p ) prime [ i ] = false ; } p += 1 ; } for ( p = 2 ; p < n + 1 ; p ++ ) { if ( prime [ p ] && isTetradic ( p ) ) Console . Write ( p + " ▁ " ) ; } } static void Main ( ) { int n = 1000 ; printTetradicPrimesLessThanN ( n ) ; } }