codeparrot/xlcost-text-to-code huggingface dataset:
Find the smallest contiguous sum pair in an Array | C # program to find the smallest sum contiguous pair ; Function to find the smallest sum contiguous pair ; Stores the contiguous pair ; Initialize minimum sum ; Checking for minimum value ; Add to pair ; Updating pair ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { public static ArrayList smallestSumpair ( int [ ] arr , int n ) { ArrayList pair = new ArrayList ( ) ; int min_sum = int . MaxValue , i ; for ( i = 1 ; i < n ; i ++ ) { if ( min_sum > ( arr [ i ] + arr [ i - 1 ] ) ) { min_sum = arr [ i ] + arr [ i - 1 ] ; if ( pair . Count == 0 ) { pair . Add ( arr [ i - 1 ] ) ; pair . Add ( arr [ i ] ) ; } else { pair [ 0 ] = arr [ i - 1 ] ; pair [ 1 ] = arr [ i ] ; } } } return pair ; } public static void Main ( string [ ] args ) { int [ ] arr = { 4 , 9 , - 3 , 2 , 0 } ; int N = arr . Length ; ArrayList pair = new ArrayList ( ) ; pair = smallestSumpair ( arr , N ) ; Console . Write ( pair [ 0 ] + " ▁ " + pair [ 1 ] ) ; } }
Add two integers of different base and represent sum in smaller base of the two | C # Program to find the sum of two integers of different bases . ; Initialize power of base ; Initialize result ; Decimal equivalent is str [ len - 1 ] * 1 + str [ len - 2 ] * base + str [ len - 3 ] * ( base ^ 2 ) + ... ; Maximum base - 36 String base_num = " " ; ; print ans in reverse order ; Driver Code ; Integer in base 10 ; Sum of integers ; Minimum Base ; Sum of integers in Min Base
using System . Collections . Generic ; using System ; using System . Linq ; using System . Text ; class GFG { static int val ( char c ) { if ( c >= '0' && c <= '9' ) return ( int ) c - '0' ; else return ( int ) c - ' A ' + 10 ; } static int convert ( string num , int bases ) { int len = ( num . Length ) ; int power = 1 ; int res = 0 ; int i ; for ( i = len - 1 ; i >= 0 ; i -- ) { res += val ( num [ i ] ) * power ; power = power * bases ; } return res ; } static void dec_to_base ( int num , int bases ) { var base_num = new StringBuilder ( ) ; while ( num > 0 ) { int dig = ( num % bases ) ; if ( dig < 10 ) base_num . Append ( dig . ToString ( ) ) ; else base_num . Append ( ( ' A ' + dig - 10 ) . ToString ( ) ) ; num /= bases ; } for ( int i = base_num . Length - 1 ; i >= 0 ; i -- ) Console . Write ( base_num [ i ] ) ; } public static void Main ( String [ ] args ) { String a = "123" ; String b = "234" ; int base_a = 6 ; int base_b = 8 ; int a10 = convert ( a , base_a ) ; int b10 = convert ( b , base_b ) ; int summ = a10 + b10 ; int min_base = Math . Min ( base_a , base_b ) ; dec_to_base ( summ , min_base ) ; } }
Sum of the products of same placed digits of two numbers | C # program to calculate the sum of same placed digits of two numbers ; Function to find the sum of the products of their corresponding digits ; Loop until one of the numbers have no digits remaining ; Driver Code
using System ; class GFG { static int sumOfProductOfDigits ( int n1 , int n2 ) { int sum = 0 ; while ( n1 > 0 && n2 > 0 ) { sum += ( ( n1 % 10 ) * ( n2 % 10 ) ) ; n1 /= 10 ; n2 /= 10 ; } return sum ; } public static void Main ( ) { int n1 = 25 ; int n2 = 1548 ; Console . WriteLine ( sumOfProductOfDigits ( n1 , n2 ) ) ; } }
Print all permutations of a number N greater than itself | C # implementation to print all the permutation greater than the integer N ; Function to print all the permutation which are greater than N itself ; Iterate and count the number of digits in N ; vector to print the permutations of N ; Store digits of N in the vector num ; Iterate over every permutation of N which is greater than N ; Print the current permutation of N ; Function to print all the permutation which are greater than N itself ; Driver Code
using System ; class GFG { static void printPermutation ( int N ) { int temp = N , count = 0 ; while ( temp > 0 ) { count ++ ; temp /= 10 ; } int [ ] num = new int [ count ] ; while ( N > 0 ) { num [ count -- - 1 ] = N % 10 ; N = N / 10 ; } while ( next_permutation ( num ) ) { for ( int i = 0 ; i < num . Length ; i ++ ) Console . Write ( num [ i ] ) ; Console . Write ( " STRNEWLINE " ) ; } } static bool next_permutation ( int [ ] p ) { for ( int a = p . Length - 2 ; a >= 0 ; -- a ) if ( p [ a ] < p [ a + 1 ] ) for ( int b = p . Length - 1 ; ; -- b ) if ( p [ b ] > p [ a ] ) { int t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; for ( ++ a , b = p . Length - 1 ; a < b ; ++ a , -- b ) { t = p [ a ] ; p [ a ] = p [ b ] ; p [ b ] = t ; } return true ; } return false ; } public static void Main ( String [ ] args ) { int N = 324 ; printPermutation ( N ) ; } }
Count of ways to represent N as sum of a prime number and twice of a square | C # implementation to count the number of ways a number can be written as sum of prime number and twice a square ; Function to mark all the prime numbers using sieve ; Initially all the numbers are marked as prime ; Loop to mark the prime numbers upto the Square root of N ; Loop to store the prime numbers in an array ; Function to find the number ways to represent a number as the sum of prime number and square of a number ; Loop to iterate over all the possible prime numbers ; Increment the count if the given number is a valid number ; Driver Code ; Function call
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static int n = 500000 - 2 ; static ArrayList v = new ArrayList ( ) ; static void sieveoferanthones ( ) { bool [ ] prime = new bool [ n + 1 ] ; Array . Fill ( prime , true ) ; for ( int i = 2 ; i <= ( int ) Math . Sqrt ( n ) ; i ++ ) { if ( prime [ i ] ) { for ( int j = i * i ; j <= n ; j += i ) { prime [ j ] = false ; } } } for ( int i = 2 ; i < n ; i ++ ) { if ( prime [ i ] ) v . Add ( i ) ; } } static void numberOfWays ( int n ) { int count = 0 ; for ( int j = 1 ; 2 * ( Math . Pow ( j , 2 ) ) < n ; j ++ ) { for ( int i = 1 ; ( int ) v [ i ] + 2 <= n ; i ++ ) { if ( n == ( int ) v [ i ] + ( 2 * ( Math . Pow ( j , 2 ) ) ) ) count ++ ; } } Console . Write ( count ) ; } public static void Main ( string [ ] args ) { sieveoferanthones ( ) ; int n = 9 ; numberOfWays ( n ) ; } }
Program to convert Degree to Radian | C # program to convert degree to radian ; Function for conversion ; Driver code
using System ; class GFG { static double Convert ( double degree ) { double pi = 3.14159265359 ; return ( degree * ( pi / 180 ) ) ; } public static void Main ( ) { double degree = 30 ; double radian = Convert ( degree ) ; Console . Write ( " { 0 : F6 } " , radian ) ; } }
Program to convert a Binary Number to Hexa | C # code to convert BCD to its HexaDecimal number ( base 16 ) . Including Header Files ; Function to convert BCD to HexaDecimal ; Iterating through the bits backwards ; Computing the HexaDecimal Number formed so far and storing it in a vector . ; Reinitializing all variables for next group . ; Printing the Hexadecimal number formed so far . ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void bcdToHexaDecimal ( char [ ] s ) { int len = s . Length , check = 0 ; int num = 0 , sum = 0 , mul = 1 ; List < char > ans = new List < char > ( ) ; for ( int i = len - 1 ; i >= 0 ; i -- ) { sum += ( s [ i ] - '0' ) * mul ; mul *= 2 ; check ++ ; if ( check == 4 i == 0 ) { if ( sum <= 9 ) ans . Add ( ( char ) ( sum + '0' ) ) ; else ans . Add ( ( char ) ( sum + 55 ) ) ; check = 0 ; sum = 0 ; mul = 1 ; } } len = ans . Count ; for ( int i = len - 1 ; i >= 0 ; i -- ) Console . Write ( ans [ i ] ) ; } public static void Main ( String [ ] args ) { String s = "100000101111" ; bcdToHexaDecimal ( s . ToCharArray ( ) ) ; } }
Find the sum of the first N Dodecagonal Numbers | C # program to find the sum of the first N dodecagonal numbers ; Function to find the N - th dodecagonal number ; Formula to calculate N - th dodecagonal number ; Function to find the sum of the first N dodecagonal numbers ; Variable to get the sum ; Iterating through the first N numbers ; Compute the sum ; Driver Code ; Display first Nth centered_decagonal number
using System ; class GFG { static int Dodecagonal_num ( int n ) { return ( 5 * n * n - 4 * n ) ; } static int sum_Dodecagonal_num ( int n ) { int summ = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { summ += Dodecagonal_num ( i ) ; } return summ ; } public static void Main ( String [ ] args ) { int n = 5 ; Console . WriteLine ( sum_Dodecagonal_num ( n ) ) ; } }
Program to check if N is a Myriagon Number | C # program for the above approach ; Function to check if N is a myriagon number ; Condition to check if the number is a myriagon number ; Driver Code ; Given Number ; Function call
using System ; class GFG { static bool isMyriagon ( int N ) { double n = ( 9996 + Math . Sqrt ( 79984 * N + 99920016 ) ) / 19996 ; return ( n - ( int ) n ) == 0 ; } static public void Main ( ) { int N = 10000 ; if ( isMyriagon ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Program to check if N is a Heptagonal Number | C # program for the above approach ; Function to check if N is a heptagonal number ; Condition to check if the number is a heptagonal number ; Driver code ; Given Number ; Function call
using System ; class GFG { public static bool isheptagonal ( int N ) { double n = ( 3 + Math . Sqrt ( 40 * N + 9 ) ) / 10 ; return ( n - ( int ) n ) == 0 ; } public static void Main ( String [ ] args ) { int N = 7 ; if ( isheptagonal ( N ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Program to check if N is a Enneadecagonal Number | C # program for the above approach ; Function to check if number N is a enneadecagonal number ; Condition to check if N is a enneadecagonal number ; Driver Code ; Given number ; Function call
using System ; class GFG { static bool isenneadecagonal ( int N ) { float n = ( float ) ( 15 + Math . Sqrt ( 136 * N + 225 ) ) / 34 ; return ( n - ( int ) n ) == 0 ; } static public void Main ( ) { int N = 19 ; if ( isenneadecagonal ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Program to check if N is a Centered Tridecagonal Number | C # program for the above approach ; Function to check if the number N is a centered tridecagonal number ; Condition to check if the N is a centered tridecagonal number ; Driver Code ; Given Number ; Function call
using System ; class GFG { static bool isCenteredtridecagonal ( int N ) { float n = ( float ) ( ( 13 + Math . Sqrt ( 104 * N + 65 ) ) / 26 ) ; return ( n - ( int ) n ) == 0 ; } public static void Main ( string [ ] args ) { int N = 14 ; if ( isCenteredtridecagonal ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Orbit counting theorem or Burnside 's Lemma | C # program for implementing the Orbit counting theorem or Burnside 's Lemma ; Function to find result using Orbit counting theorem or Burnside 's Lemma ; According to Burnside 's Lemma  calculate distinct ways for each  rotation ; Find GCD ; Divide By N ; Print the distinct ways ; Driver Code ; N stones and M colors ; Function call
using System ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static void countDistinctWays ( int N , int M ) { int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int K = gcd ( i , N ) ; ans += ( int ) Math . Pow ( M , K ) ; } ans /= N ; Console . Write ( ans ) ; } public static void Main ( string [ ] args ) { int N = 4 , M = 3 ; countDistinctWays ( N , M ) ; } }
Find the Nth natural number which is not divisible by A | C # code to find the Nth number which is not divisible by A from the series ; Find the quotient and the remainder when k is divided by n - 1 ; If the remainder is not 0 multiply n by q and subtract 1 if remainder is 0 then multiply n by q and add the remainder ; Print the answer ; Driver code
using System ; class GFG { static void findNum ( int n , int k ) { int q = k / ( n - 1 ) ; int r = k % ( n - 1 ) ; int a = 0 ; if ( r != 0 ) a = ( n * q ) + r ; else a = ( n * q ) - 1 ; Console . WriteLine ( a ) ; } public static void Main ( String [ ] args ) { int A = 4 ; int N = 6 ; findNum ( A , N ) ; } }
Count the nodes in the given Tree whose weight is a Perfect Number | C # implementation to count the nodes in the given tree whose weight is a Perfect Number ; Function that returns true if n is perfect ; Variable to store sum of divisors ; Find all divisors and add them ; Check if sum of divisors is equal to n , then n is a perfect number ; Function to perform dfs ; If weight of the current node is a perfect number ; Driver code ; Weights of the node ; Edges of the tree
using System ; using System . Collections . Generic ; class GFG { static int ans = 0 ; static List < int > [ ] graph = new List < int > [ 100 ] ; static int [ ] weight = new int [ 100 ] ; static bool isPerfect ( int n ) { int sum = 1 ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i != n ) sum = sum + i + n / i ; else sum = sum + i ; } } if ( sum == n && n != 1 ) return true ; return false ; } static void dfs ( int node , int parent ) { if ( isPerfect ( weight [ node ] ) ) ans += 1 ; foreach ( int to in graph [ node ] ) { if ( to == parent ) continue ; dfs ( to , node ) ; } } public static void Main ( String [ ] args ) { for ( int i = 0 ; i < graph . Length ; i ++ ) graph [ i ] = new List < int > ( ) ; weight [ 1 ] = 5 ; weight [ 2 ] = 10 ; weight [ 3 ] = 11 ; weight [ 4 ] = 8 ; weight [ 5 ] = 6 ; graph [ 1 ] . Add ( 2 ) ; graph [ 2 ] . Add ( 3 ) ; graph [ 2 ] . Add ( 4 ) ; graph [ 1 ] . Add ( 5 ) ; dfs ( 1 , 1 ) ; Console . Write ( ans ) ; } }
Minimum cost to merge numbers from 1 to N | C # program to find the Minimum cost to merge numbers from 1 to N . ; Function returns the minimum cost ; Min Heap representation ; Add all elements to heap ; First minimum ; Second minimum ; Multiply them ; Add to the cost ; Push the product into the heap again ; Return the optimal cost ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int GetMinCost ( int N ) { List < int > pq = new List < int > ( ) ; for ( int i = 1 ; i <= N ; i ++ ) { pq . Add ( i ) ; } int cost = 0 ; pq . Sort ( ) ; while ( pq . Count > 1 ) { int mini = pq [ 0 ] ; pq . RemoveAt ( 0 ) ; int secondmini = pq [ 0 ] ; pq . RemoveAt ( 0 ) ; int current = mini * secondmini ; cost += current ; pq . Add ( current ) ; pq . Sort ( ) ; } return cost ; } static void Main ( ) { int N = 5 ; Console . WriteLine ( GetMinCost ( N ) ) ; } }
Permutation of first N positive integers such that prime numbers are at prime indices | Set 2 | C # program to count permutations from 1 to N such that prime numbers occurr at prime indices ;  ; Computing count of prime numbers using sieve ; Computing permutations for primes ; Computing permutations for non - primes ; Driver code
using System ; class GFG { static int numPrimeArrangements ( int n ) { bool [ ] prime = new bool [ n + 1 ] ; for ( int i = 0 ; i < prime . Length ; i ++ ) prime [ i ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( prime [ i ] ) { for ( int factor = 2 ; factor * i <= n ; factor ++ ) prime [ factor * i ] = false ; } } int primeIndices = 0 ; for ( int i = 1 ; i <= n ; i ++ ) if ( prime [ i ] ) primeIndices ++ ; int mod = ( int ) ( 1e9 + 7 ) , res = 1 ; for ( int i = 1 ; i <= primeIndices ; i ++ ) res = ( int ) ( ( 1L * res * i ) % mod ) ; for ( int i = 1 ; i <= ( n - primeIndices ) ; i ++ ) res = ( int ) ( ( 1L * res * i ) % mod ) ; return res ; } public static void Main ( String [ ] args ) { int N = 5 ; Console . Write ( numPrimeArrangements ( N ) ) ; } }
Probability of getting K heads in N coin tosses | C # program to find probability of getting K heads in N coin tosses ; Function to calculate factorial ; Apply the formula ; Driver function ; Call count_heads with n and r
using System ; public class GFG { static int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static double count_heads ( int n , int r ) { double output ; output = fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; output = output / ( Math . Pow ( 2 , n ) ) ; return output ; } public static void Main ( String [ ] args ) { int n = 4 , r = 3 ; Console . Write ( count_heads ( n , r ) ) ; } }
Largest component size in a graph formed by connecting non | C # program to implement the above approach ; Mark this node as visited ; Apply dfs and add nodes belonging to this component ; Create graph and store in adjacency list form ; Iterate over all pair of nodes ; If not co - prime ; Build undirected graph ; Visited array for dfs ; Utility gcd ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int dfs ( int u , List < int > [ ] adj , int [ ] vis ) { vis [ u ] = 1 ; int componentSize = 1 ; foreach ( int it in adj [ u ] ) { if ( vis [ it ] == 0 ) { componentSize += dfs ( it , adj , vis ) ; } } return componentSize ; } static int maximumComponentSize ( int [ ] a , int n ) { List < int > [ ] adj = new List < int > [ n ] ; for ( int i = 0 ; i < adj . Length ; i ++ ) adj [ i ] = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( __gcd ( a [ i ] , a [ j ] ) > 1 ) adj [ i ] . Add ( j ) ; adj [ j ] . Add ( i ) ; } } int answer = 0 ; int [ ] vis = new int [ n ] ; for ( int k = 0 ; k < n ; k ++ ) { vis [ k ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { if ( vis [ i ] == 0 ) { answer = Math . Max ( answer , dfs ( i , adj , vis ) ) ; } } return answer ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void Main ( String [ ] args ) { int n = 8 ; int [ ] A = { 2 , 3 , 6 , 7 , 4 , 12 , 21 , 39 } ; Console . Write ( maximumComponentSize ( A , n ) ) ; } }
Largest component size in a graph formed by connecting non | C # program to implement the above approach ; Smallest prime factor ; Sieve of Eratosthenes ; Is spf [ i ] = 0 , then it 's prime ; Smallest prime factor of all multiples is i ; Prime factorise n , and store prime factors in set s ; For implementing DSU ; Root of component of node i ; Finding root as well as applying path compression ; Merging two components ; Find roots of both components ; If already belonging to the same compenent ; Union by rank , the rank in this case is sizeContainer of the component . Smaller sizeContainer will be merged into larger , so the larger 's root will be  readonly root ; Function to find the maximum sized container ; Initialise the parents , and component sizeContainer ; Intitally all component sizeContainers are 1 ans each node it parent of itself ; Store prime factors of a [ i ] in s ; If this prime is seen as a factor for the first time ; If not then merge with that component in which this prime was previously seen ; Maximum of sizeContainer of all components ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int [ ] spf = new int [ 100005 ] ; static void sieve ( ) { for ( int i = 2 ; i < 100005 ; i ++ ) { if ( spf [ i ] == 0 ) { spf [ i ] = i ; for ( int j = 2 * i ; j < 100005 ; j += i ) { if ( spf [ j ] == 0 ) spf [ j ] = i ; } } } } static void factorize ( int n , HashSet < int > s ) { while ( n > 1 ) { int z = spf [ n ] ; s . Add ( z ) ; while ( n % z == 0 ) n /= z ; } } static int [ ] id = new int [ 100005 ] ; static int [ ] par = new int [ 100005 ] ; static int [ ] sizeContainer = new int [ 100005 ] ; static int root ( int i ) { if ( par [ i ] == i ) return i ; else return par [ i ] = root ( par [ i ] ) ; } static void merge ( int a , int b ) { int p = root ( a ) ; int q = root ( b ) ; if ( p == q ) return ; if ( sizeContainer [ p ] > sizeContainer [ q ] ) { p = p + q ; q = p - q ; p = p - q ; } par [ p ] = q ; sizeContainer [ q ] += sizeContainer [ p ] ; } static int maximumComponentsizeContainer ( int [ ] a , int n ) { for ( int i = 0 ; i < 100005 ; i ++ ) { par [ i ] = i ; sizeContainer [ i ] = 1 ; } sieve ( ) ; for ( int i = 0 ; i < n ; i ++ ) { HashSet < int > s = new HashSet < int > ( ) ; factorize ( a [ i ] , s ) ; foreach ( int it in s ) { if ( id [ it ] == 0 ) id [ it ] = i + 1 ; else merge ( i + 1 , id [ it ] ) ; } } int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) answer = Math . Max ( answer , sizeContainer [ i ] ) ; return answer ; } public static void Main ( String [ ] args ) { int n = 8 ; int [ ] A = { 2 , 3 , 6 , 7 , 4 , 12 , 21 , 39 } ; Console . Write ( maximumComponentsizeContainer ( A , n ) ) ; } }
Count of nodes in a Binary Tree whose child is its prime factors | C # program for Counting nodes whose immediate children are its factors ; To store all prime numbers ; Create a bool array " prime [ 0 . . N ] " and initialize all its entries 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 greater than or equal to the square of it numbers which are multiples of p and are less than p ^ 2 are already marked . ; A Tree node ; Utility function to create a new node ; Function to check if immediate children of a node are its factors or not ; Function to get the count of full Nodes in a binary tree ; If tree is empty ; Initialize count of full nodes having children as their factors ; If only right child exist ; If only left child exist ; Both left and right child exist ; Check for left child ; Check for right child ; Driver Code ; Create Binary Tree as shown ; To save all prime numbers ; Print Count of all nodes having children as their factors
using System ; using System . Collections . Generic ; public class GFG { static int N = 1000000 ; static List < int > prime = new List < int > ( ) ; static void SieveOfEratosthenes ( ) { bool [ ] check = new bool [ N + 1 ] ; for ( int i = 0 ; i <= N ; i += 1 ) check [ i ] = true ; for ( int p = 2 ; p * p <= N ; p ++ ) { if ( check [ p ] == true ) { prime . Add ( p ) ; for ( int i = p * p ; i <= N ; i += p ) check [ i ] = false ; } } } class Node { public int key ; public Node left , right ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = temp . right = null ; return ( temp ) ; } static bool IsChilrenPrimeFactor ( Node parent , Node a ) { if ( prime [ a . key ] > 0 && ( parent . key % a . key == 0 ) ) return true ; else return false ; } static int GetCount ( Node node ) { if ( node == null ) return 0 ; List < Node > q = new List < Node > ( ) ; int count = 0 ; q . Add ( node ) ; while ( q . Count != 0 ) { Node temp = q [ 0 ] ; q . RemoveAt ( 0 ) ; if ( temp . left == null && temp . right != null ) { if ( IsChilrenPrimeFactor ( temp , temp . right ) ) count ++ ; } else { if ( temp . right == null && temp . left != null ) { if ( IsChilrenPrimeFactor ( temp , temp . left ) ) count ++ ; } else { if ( temp . left != null && temp . right != null ) { if ( IsChilrenPrimeFactor ( temp , temp . right ) && IsChilrenPrimeFactor ( temp , temp . left ) ) count ++ ; } } } if ( temp . left != null ) q . Add ( temp . left ) ; if ( temp . right != null ) q . Add ( temp . right ) ; } return count ; } public static void Main ( String [ ] args ) { Node root = newNode ( 10 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 5 ) ; root . right . left = newNode ( 18 ) ; root . right . right = newNode ( 12 ) ; root . right . left . left = newNode ( 2 ) ; root . right . left . right = newNode ( 3 ) ; root . right . right . left = newNode ( 3 ) ; root . right . right . right = newNode ( 14 ) ; root . right . right . right . left = newNode ( 7 ) ; SieveOfEratosthenes ( ) ; Console . Write ( GetCount ( root ) + " STRNEWLINE " ) ; } }