codeparrot/xlcost-text-to-code huggingface dataset:
Print all distinct Coprime sets possible from 1 to N | C # implementation to print all distinct co - prime sets possible for numbers from 1 to N ; Function to print all co - prime sets ; Check if n is less than 4 then simply print all values till n ; For all the values of n > 3 ; Check if n is even then every set will contain 2 adjacent elements up - to n ; If n is odd then every set will contain 2 adjacent element except the last set which will have last three elements ; Last element for odd case ; Driver code
using System ; class GFG { static void coPrimeSet ( int n ) { int firstadj , secadj ; if ( n < 4 ) { Console . Write ( " ( ▁ " ) ; for ( int i = 1 ; i <= n ; i ++ ) Console . Write ( i + " , ▁ " ) ; Console . Write ( " ) STRNEWLINE " ) ; } else { if ( n % 2 == 0 ) { for ( int i = 0 ; i < n / 2 ; i ++ ) { firstadj = 2 * i + 1 ; secadj = 2 * i + 2 ; Console . Write ( " ( " + firstadj + " , ▁ " + secadj + " ) STRNEWLINE " ) ; } } else { for ( int i = 0 ; i < n / 2 - 1 ; i ++ ) { firstadj = 2 * i + 1 ; secadj = 2 * i + 2 ; Console . Write ( " ( " + firstadj + " , ▁ " + secadj + " ) STRNEWLINE " ) ; } Console . Write ( " ( " + ( n - 2 ) + " , ▁ " + ( n - 1 ) + " , ▁ " + n + " ) STRNEWLINE " ) ; } } } public static void Main ( ) { int n = 5 ; coPrimeSet ( n ) ; } }
Find the sequence number of a triangular number | C # code to print sequence number of a triangular number ; If N is not tringular number
using System ; class GFG { public static void Main ( ) { int N = 21 ; int A = ( int ) ( Math . Sqrt ( 2 * N + 0.25 ) - 0.5 ) ; int B = A ; if ( B != A ) Console . Write ( " - 1" ) ; else Console . Write ( B ) ; } }
Count subarrays with sum equal to its XOR value | C # program to count the number of subarrays such that Xor of all the elements of that subarray is equal to sum of the elements ; Function to count the number of subarrays such that Xor of all the elements of that subarray is equal to sum of the elements ; Maintain two pointers left and right ; Iterating through the array ; Calculate the window where the above condition is satisfied ; Count will be ( right - left ) ; Remove the previous element as it is already included ; Driver code
using System ; class GFG { static long operation ( int [ ] arr , int N ) { int right = 0 ; int num = 0 ; long ans = 0 ; for ( int left = 0 ; left < N ; left ++ ) { while ( right < N && num + arr [ right ] == ( num ^ arr [ right ] ) ) { num += arr [ right ] ; right ++ ; } ans += right - left ; if ( left == right ) right ++ ; else num -= arr [ left ] ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int N = arr . Length ; Console . WriteLine ( operation ( arr , N ) ) ; } }
Count of pairs in an Array whose sum is Prime | C # code to find number of pairs of elements in an array whose sum is prime ; Function for Sieve Of Eratosthenes ; Function to count total number of pairs of elements whose sum is prime ; Driver code
using System ; class GFG { public static bool [ ] sieveOfEratosthenes ( int N ) { bool [ ] isPrime = new bool [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { isPrime [ i ] = true ; } isPrime [ 0 ] = false ; isPrime [ 1 ] = false ; for ( int i = 2 ; i * i <= N ; i ++ ) { if ( isPrime [ i ] == true ) { int j = 2 ; while ( i * j <= N ) { isPrime [ i * j ] = false ; j ++ ; } } } return isPrime ; } public static int numPairsWithPrimeSum ( int [ ] arr , int n ) { int N = 2 * 1000000 ; bool [ ] isPrime = sieveOfEratosthenes ( N ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int sum = arr [ i ] + arr [ j ] ; if ( isPrime [ sum ] ) { count ++ ; } } } return count ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . Length ; Console . WriteLine ( numPairsWithPrimeSum ( arr , n ) ) ; } }
Count of numbers in Array ending with digits of number N | C # program to find the count of numbers in Array ending with digits of number N ; Array to keep the track of digits occurred Initially all are 0 ( false ) ; Function to initialize 1 ( true ) if the digit is present ; Variable to store the last digit ; Loop to iterate through every digit of the number N ; Updating the array according to the presence of the digit in n at the array index ; Function to check if the numbers in the array end with the digits of the number N ; Variable to store the count ; Variable to store the last digit ; Checking the presence of the last digit in N ; Function to find the required count ; Driver code ; Preprocessing
using System ; class GFG { public static int [ ] digit = new int [ 10 ] ; public static void digitsPresent ( int n ) { int lastDigit ; while ( n != 0 ) { lastDigit = n % 10 ; digit [ lastDigit ] = 1 ; n /= 10 ; } } public static int checkLastDigit ( int num ) { int count = 0 ; int lastDigit ; lastDigit = num % 10 ; if ( digit [ lastDigit ] == 1 ) count ++ ; return count ; } public static void findCount ( int N , int K , int [ ] arr ) { int count = 0 ; for ( int i = 0 ; i < K ; i ++ ) { count = checkLastDigit ( arr [ i ] ) == 1 ? count + 1 : count ; } Console . WriteLine ( count ) ; } static public void Main ( ) { int N = 1731 ; digitsPresent ( N ) ; int K = 5 ; int [ ] arr = { 57 , 6786 , 1111 , 3 , 9812 } ; findCount ( N , K , arr ) ; } }
Check if count of even divisors of N is equal to count of odd divisors | C # code for the above program ; Function to check if count of even and odd divisors are equal ; If ( n - 2 ) % 4 is an integer , then return true else return false ; Driver code ; Given number ; Function call
using System ; class GFG { static bool divisorsSame ( int n ) { return ( n - 2 ) % 4 == 0 ; } public static void Main ( ) { int N = 6 ; if ( divisorsSame ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Nth term of a sequence formed by sum of current term with product of its largest and smallest digit | C # program for the above approach . ; Function to find integer ; Because 1 st integer is K itself ; Initialize min_d and max_d ; Updating min_d and max_d ; Break if min digit is 0 ; Driver code
using System ; class GFG { static int find ( int K , int N ) { N -- ; while ( N -- != 0 ) { int curr_term = K ; int min_d = 9 ; int max_d = 0 ; while ( curr_term > 0 ) { int r = curr_term % 10 ; min_d = Math . Min ( min_d , r ) ; max_d = Math . Max ( max_d , r ) ; curr_term = ( int ) ( curr_term / 10 ) ; } if ( min_d == 0 ) { break ; } K = K + min_d * max_d ; } return K ; } public static void Main ( ) { int K = 487 ; int N = 2 ; Console . Write ( find ( K , N ) ) ; } }
Count of subarrays whose sum is a perfect square | C # code for the above approach . ; Function to find count of subarrays whose sum is a perfect square . ; To search for index with ( current prefix sum - j * j ) ; Storing the prefix sum ; Used to track the minimum value in prefixSum ; Calculating the prefixSum and tracking the prefixMin ; Below statement is used if array contains negative numbers ; Counts the no of subarrays with perfect square sum ; As 0 is a perfect square , so we initialize 0 th index - key with value 1 ; Here we count the perfect square subarray sum by searching if there is a prefix with sum = ( current prefixSum - ( sq * sq ) ) ; Increasing our subarray count ; Increasing the current prefixSum index value in map by 1 to count the other perfect squares while traversing further ; Driver code ; Printing the result
using System ; using System . Collections . Generic ; class GFG { static long countSubarrays ( int [ ] arr , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; int [ ] prefixSum = new int [ n ] ; int prefixMin = 0 ; prefixSum [ 0 ] = arr [ 0 ] ; prefixMin = Math . Min ( prefixMin , prefixSum [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { prefixSum [ i ] = prefixSum [ i - 1 ] + arr [ i ] ; prefixMin = Math . Min ( prefixMin , prefixSum [ i ] ) ; } long countSubs = 0 ; mp . Add ( 0 , 1 ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; prefixSum [ i ] - j * j >= prefixMin ; j ++ ) { if ( mp . ContainsKey ( prefixSum [ i ] - j * j ) ) countSubs += mp [ prefixSum [ i ] - j * j ] ; } if ( mp . ContainsKey ( prefixSum [ i ] ) ) { mp [ prefixSum [ i ] ] ++ ; } else { mp . Add ( prefixSum [ i ] , 1 ) ; } } return countSubs ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 3 , - 5 , 6 , - 7 , 4 } ; int n = arr . Length ; long ans = countSubarrays ( arr , n ) ; Console . Write ( ans ) ; } }
Find if two given Quadratic equations have common roots or not | C # Program to Find if two given quadratic equations have common roots or not ; Function to check if 2 quadratic equations have common roots or not . ; Driver code
using System ; class GFG { static bool checkSolution ( float a1 , float b1 , float c1 , float a2 , float b2 , float c2 ) { return ( ( a1 / a2 ) == ( b1 / b2 ) && ( b1 / b2 ) == ( c1 / c2 ) ) ; } public static void Main ( string [ ] args ) { float a1 = 1 , b1 = - 5 , c1 = 6 ; float a2 = 2 , b2 = - 10 , c2 = 12 ; if ( checkSolution ( a1 , b1 , c1 , a2 , b2 , c2 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Check if roots of a Quadratic Equation are numerically equal but opposite in sign or not | C # program to check if roots of a Quadratic Equation are numerically equal but opposite in sign or not ; Function to find the required answer ; Driver code
using System ; class GFG { static void checkSolution ( int a , int b , int c ) { if ( b == 0 ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } public static void Main ( ) { int a = 2 , b = 0 , c = 2 ; checkSolution ( a , b , c ) ; } }
Count of index pairs in array whose range product is a positive integer | C # program to find the count of index pairs in the array positive range product ; Condition if number of negative elements is even then increase even_count ; Otherwise increase odd_count ; Condition if current element is negative ; Condition if number of negative elements is even then add even_count in answer ; Otherwise add odd_count in answer ; Driver Code
using System ; class GFG { public static void positiveProduct ( int [ ] arr , int n ) { int even_count = 0 ; int odd_count = 0 ; int total_count = 0 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( total_count % 2 == 0 ) { even_count ++ ; } else { odd_count ++ ; } if ( arr [ i ] < 0 ) { total_count ++ ; } if ( total_count % 2 == 0 ) ans += even_count ; else ans += odd_count ; } Console . WriteLine ( ans ) ; } public static void Main ( String [ ] args ) { int [ ] A = { 5 , - 3 , 3 , - 1 , 1 } ; int size = A . Length ; positiveProduct ( A , size ) ; } }
Pair of integers having difference of their fifth power as X | C # implementation to find a pair of integers A & B such that difference of fifth power is equal to the given number X ; Function to find a pair of integers A & B such that difference of fifth power is equal to the given number X ; Loop to choose every possible pair with in the range ; Check if equation holds ; Driver code ; Function call
using System ; class GFG { static void findPair ( int x ) { int lim = 120 ; for ( int i = - lim ; i <= lim ; i ++ ) { for ( int j = - lim ; j <= lim ; j ++ ) { if ( Math . Pow ( i , 5 ) - Math . Pow ( j , 5 ) == x ) { Console . Write ( i + " ▁ " + j + " STRNEWLINE " ) ; return ; } } } Console . Write ( " - 1" ) ; } public static void Main ( String [ ] args ) { int X = 33 ; findPair ( X ) ; } }
Sum of GCD of all numbers upto N with N itself | C # program to find the sum of GCD of all integers up to N with N itself ; Function to find sum of GCD of each numbers ; Consider all prime factors of no . and subtract their multiples from result ; Check if p is a prime factor ; If yes , then update no and result ; If no has a prime factor greater than Math . Sqrt ( n ) then at - most one such prime factor exists ; Return the result ; Finding GCD of pairs ; Calculate the divisors ; Return count of numbers from 1 to N with GCD d with N ; Check if d1 and d2 are equal then skip this ; Driver code
using System ; class GFG { static int getCount ( int d , int n ) { int no = n / d ; int result = no ; for ( int p = 2 ; p * p <= no ; ++ p ) { if ( no % p == 0 ) { while ( no % p == 0 ) no /= p ; result -= result / p ; } } if ( no > 1 ) result -= result / no ; return result ; } static int sumOfGCDofPairs ( int n ) { int res = 0 ; for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { int d1 = i ; int d2 = n / i ; res += d1 * getCount ( d1 , n ) ; if ( d1 != d2 ) res += d2 * getCount ( d2 , n ) ; } } return res ; } public static void Main ( String [ ] args ) { int n = 12 ; Console . Write ( sumOfGCDofPairs ( n ) ) ; } }
Check whether Array represents a Fibonacci Series or not | C # program to check if the elements of a given array can form a fibonacci series ; Returns true if a permutation of arr [ 0. . n - 1 ] can form a fibonacci series ; Sort array ; After sorting , check if every element is equal to the sum of previous 2 elements ; Driver code
using System ; class GFG { public static bool checkIsFibonacci ( int [ ] arr , int n ) { if ( n == 1 n == 2 ) return true ; Array . Sort ( arr ) ; for ( int i = 2 ; i < n ; i ++ ) { if ( ( arr [ i - 1 ] + arr [ i - 2 ] ) != arr [ i ] ) return false ; } return true ; } public static void Main ( string [ ] args ) { int [ ] arr = { 8 , 3 , 5 , 13 } ; int n = arr . Length ; if ( checkIsFibonacci ( arr , n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Last digit in a power of 2 | C # program to find last digit in a power of 2. ; Corner case ; Find the shift in current cycle and return value accordingly ; return 6 ; When n % 4 == 0 ; Driver code
using System ; class GFG { static int lastDigit2PowerN ( int n ) { if ( n == 0 ) return 1 ; else if ( n % 4 == 1 ) return 2 ; else if ( n % 4 == 2 ) return 4 ; else if ( n % 4 == 3 ) return 8 ; else } public static void Main ( string [ ] args ) { for ( int n = 0 ; n < 20 ; n ++ ) { Console . Write ( lastDigit2PowerN ( n ) + " ▁ " ) ; } } }
Sum of all subsequences of length K | C # implementation to find sum of all subsequences of length K ; Function to find nCr ; Function that returns factorial of n ; Function for finding sum of all K length subsequences ; Calculate the sum of array ; Calculate nCk ; Return the final result ; Driver code
using System ; class GFG { static int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } static int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static int sumSubsequences ( int [ ] arr , int n , int k ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } int kLengthSubSequence ; kLengthSubSequence = nCr ( n , k ) ; int ans = sum * ( ( k * kLengthSubSequence ) / n ) ; return ans ; } static void Main ( ) { int [ ] arr = { 7 , 8 , 9 , 2 } ; int K = 2 ; int n = arr . Length ; Console . Write ( sumSubsequences ( arr , n , K ) ) ; } }
Sum of first K numbers which are not divisible by N | C # program to calculate the sum of first K numbers not divisible by N ; Function to find the sum ; Find the last multiple of N ; Find the K - th non - multiple of N ; Calculate the sum of all elements from 1 to val ; Calculate the sum of all multiples of N between 1 to val ; Driver code
using System ; class GFG { static int findSum ( int n , int k ) { int val = ( k / ( n - 1 ) ) * n ; int rem = k % ( n - 1 ) ; if ( rem == 0 ) { val = val - 1 ; } else { val = val + rem ; } int sum = ( val * ( val + 1 ) ) / 2 ; int x = k / ( n - 1 ) ; int sum_of_multiples = ( x * ( x + 1 ) * n ) / 2 ; sum -= sum_of_multiples ; return sum ; } public static void Main ( String [ ] args ) { int n = 7 , k = 13 ; Console . WriteLine ( findSum ( n , k ) ) ; } }
Count of the non | C # program to find count of non - prime divisors of given number ; Function to factors of the given number ; Loop to find the divisors of the number 2 ; Loop to find the divisors of the given number upto SQRT ( N ) ; Condition to check if the rest number is also a prime number ; Function to find the non - prime divisors of the given number ; Loop to count the number of the total divisors of given number ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static List < int > getFactorization ( int x ) { int count = 0 ; List < int > v = new List < int > ( ) ; while ( x % 2 == 0 ) { count ++ ; x = x / 2 ; } if ( count != 0 ) v . Add ( count ) ; for ( int i = 3 ; i <= Math . Sqrt ( x ) ; i += 2 ) { count = 0 ; while ( x % i == 0 ) { count ++ ; x /= i ; } if ( count != 0 ) v . Add ( count ) ; } if ( x > 1 ) { v . Add ( 1 ) ; } return v ; } static int nonPrimeDivisors ( int N ) { List < int > v = getFactorization ( N ) ; int ret = 1 ; for ( int i = 0 ; i < v . Count ; i ++ ) ret = ret * ( v [ i ] + 1 ) ; ret = ret - v . Count ; return ret ; } public static void Main ( String [ ] args ) { int N = 8 ; Console . WriteLine ( nonPrimeDivisors ( N ) ) ; } }
Check if a number is Full Fibonacci or not | C # program to check if a given number is a full fibonacci number or not ; A utility function that returns true if x is perfect square ; Returns true if N is a fibonacci number and false otherwise ; N is fibonacci if one of 5 * N ^ 2 + 4 or 5 * N ^ 2 - 4 or both is a perferct square ; Function to check digits ; Check if all digits are fibonacci or not ; Extract digit ; Check if the current digit is not fibonacci ; Function to check and return if N is a full fibonacci number or not ; Driver code
using System ; class GFG { static bool isPerfectSquare ( int x ) { int s = ( int ) Math . Sqrt ( x ) ; return ( s * s == x ) ; } static bool isFibonacci ( int n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } static bool checkDigits ( int n ) { while ( n != 0 ) { int dig = n % 10 ; if ( dig == 4 && dig == 6 && dig == 7 && dig == 9 ) return false ; n /= 10 ; } return true ; } static bool isFullfibonacci ( int n ) { return ( checkDigits ( n ) && isFibonacci ( n ) ) ; } public static void Main ( String [ ] args ) { int n = 13 ; if ( isFullfibonacci ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Check whether a large number is divisible by 53 or not | C # program to check whether a number is divisible by 53 or not ; Function to check if the number is divisible by 53 or not ; Driver Code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static bool isDivisible ( char [ ] s ) { while ( s . Length > 4 ) { int l = s . Length - 1 ; int x = ( s [ l ] - '0' ) * 37 ; s = reverse ( s ) ; char [ ] tmp = new char [ s . Length - 1 ] ; Array . Copy ( s , 1 , tmp , 0 , s . Length - 1 ) ; s = tmp ; int i = 0 , carry = 0 ; while ( x > 0 ) { int d = ( s [ i ] - '0' ) - ( x % 10 ) - carry ; if ( d < 0 ) { d += 10 ; carry = 1 ; } else carry = 0 ; s [ i ] = ( char ) ( d + '0' ) ; x /= 10 ; i ++ ; } while ( carry > 0 && i < l ) { int d = ( s [ i ] - '0' ) - carry ; if ( d < 0 ) { d += 10 ; carry = 1 ; } else carry = 0 ; s [ i ] = ( char ) ( d + '0' ) ; i ++ ; } s = reverse ( s ) ; } int num = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) { num = num * 10 + ( s [ i ] - '0' ) ; } if ( num % 53 == 0 ) return true ; else return false ; } static char [ ] reverse ( char [ ] a ) { int l , r = a . Length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return a ; } public static void Main ( string [ ] args ) { string N = "18432462191076" ; if ( isDivisible ( N . ToCharArray ( ) ) ) Console . Write ( " Yes " + " STRNEWLINE " ) ; else Console . Write ( " No " + " STRNEWLINE " ) ; } }
Check whether two numbers are in silver ratio | C # implementation to check whether two numbers are in silver ratio with each other ; Function to check that two numbers are in silver ratio ; Swapping the numbers such that A contains the maximum number between these numbers ; First Ratio ; Second Ratio ; Condition to check that two numbers are in silver ratio ; Driver Code ; Function call
using System ; class GFG { static bool checksilverRatio ( double a , double b ) { if ( a < b ) { a = a + b ; b = a - b ; a = a - b ; } double ratio1 = ( ( a / b ) * 1000 ) / 1000 ; double ratio2 = ( int ) ( ( ( 2 * a + b ) / a ) * 1000 ) ; ratio2 = ratio2 / 1000 ; if ( ratio1 == ratio2 && ( int ) ( ratio1 - 2.414 ) == 0 ) { Console . WriteLine ( " Yes " ) ; return true ; } else { Console . WriteLine ( " No " ) ; return false ; } } public static void Main ( ) { double a = 2.414 ; double b = 1 ; checksilverRatio ( a , b ) ; } }
Nth term where K + 1 th term is product of Kth term with difference of max and min digit of Kth term | C # implementation to find the value of the given function for the value ; Function to find minimum digit in the decimal representation of N ; Loop to find the minimum digit in the number ; Function to find maximum digit in the decimal representation of N ; Loop to find the maximum digit in the number ; Function to find the value of the given function ; Loop to compute the values of the given number ; Driver Code ; Function Call
using System ; class GFG { static int MIN ( int n ) { int ans = 11 ; while ( n > 0 ) { ans = Math . Min ( ans , n % 10 ) ; n /= 10 ; } return ans ; } static int MAX ( int n ) { int ans = - 1 ; while ( n > 0 ) { ans = Math . Max ( ans , n % 10 ) ; n /= 10 ; } return ans ; } static void Find_value ( int n , int k ) { k -- ; int x = 0 ; int y = 0 ; while ( k -- > 0 ) { x = MIN ( n ) ; y = MAX ( n ) ; if ( y - x == 0 ) break ; n *= ( y - x ) ; } Console . Write ( n ) ; } public static void Main ( String [ ] args ) { int N = 487 , D = 5 ; Find_value ( N , D ) ; } }
Program to check if N is a Decagonal Number | C # program for the above approach ; Function to check if N is a decagonal Number ; Condition to check if the number is a decagonal number ; Driver Code ; Given Number ; Function call
using System ; class GFG { static bool isdecagonal ( int N ) { double n = ( 3 + Math . Sqrt ( 16 * N + 9 ) ) / 8 ; return ( n - ( int ) n ) == 0 ; } static public void Main ( ) { int N = 10 ; if ( isdecagonal ( N ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Program to check if N is a Octadecagon number | C # program for the above approach ; Function to check if N is a octadecagon Number ; Condition to check if the number is a octadecagon number ; Driver Code ; Given Number ; Function call
using System ; class GFG { public static bool isOctadecagon ( int N ) { double n = ( 14 + Math . Sqrt ( 128 * N + 196 ) ) / 32 ; return ( n - ( int ) n ) == 0 ; } public static void Main ( String [ ] args ) { int N = 18 ; if ( isOctadecagon ( N ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Count of subsequences which consists exactly K prime numbers | C # implementation to find the count of subsequences which consist exactly K primes ; Returns factorial of n ; Function to return total number of combinations ; Function check whether a number is prime or not ; Corner case ; Check from 2 to n - 1 ; Function for finding number of subsequences which consists exactly K primes ; If number of primes are less than k ; Driver code
using System ; class GFG { static int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } static bool isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static int countSubsequences ( int [ ] arr , int n , int k ) { int countPrime = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( isPrime ( arr [ i ] ) ) countPrime ++ ; } if ( countPrime < k ) return 0 ; return nCr ( countPrime , k ) * ( int ) Math . Pow ( 2 , ( n - countPrime ) ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; int K = 3 ; int n = arr . Length ; Console . WriteLine ( countSubsequences ( arr , n , K ) ) ; } }