codeparrot/xlcost-text-to-code huggingface dataset:
Minimum sum possible by removing all occurrences of any array element | C # program for the above approach ; Function to find minimum sum after deletion ; Stores frequency of array elements ; Traverse the array ; Calculate sum ; Update frequency of the current element ; Stores the minimum sum required ; Traverse map ; Find the minimum sum obtained ; Return minimum sum ; Driver code ; Input array ; Size of array
using System ; using System . Collections . Generic ; public class GFG { static int minSum ( int [ ] A , int N ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += A [ i ] ; if ( mp . ContainsKey ( A [ i ] ) ) { mp [ A [ i ] ] = mp [ A [ i ] ] + 1 ; } else { mp . Add ( A [ i ] , 1 ) ; } } int minSum = int . MaxValue ; foreach ( KeyValuePair < int , int > it in mp ) { minSum = Math . Min ( minSum , sum - ( it . Key * it . Value ) ) ; } return minSum ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 5 , 6 , 6 } ; int N = arr . Length ; Console . Write ( minSum ( arr , N ) + " STRNEWLINE " ) ; } }
Maximum difference between a pair of adjacent elements by excluding every element once | C # program for the above approach ; Function to calculate maximum difference between adjacent elements excluding every array element once ; Traverse the array ; Stores the maximum diff ; Check for maximum adjacent element ; Exclude current element ; Update maximum difference ; Update previous value ; Append the result into a vector ; Print the result ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { static void maxAdjacent ( int [ ] arr , int N ) { List < int > res = new List < int > ( ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { int prev = arr [ 0 ] ; int maxi = Int32 . MinValue ; for ( int j = 1 ; j < N ; j ++ ) { if ( i == j ) continue ; maxi = Math . Max ( maxi , Math . Abs ( arr [ j ] - prev ) ) ; prev = arr [ j ] ; } res . Add ( maxi ) ; } foreach ( int x in res ) { Console . Write ( x + " ▁ " ) ; } Console . WriteLine ( ) ; } static public void Main ( ) { int [ ] arr = { 1 , 3 , 4 , 7 , 8 } ; int N = arr . Length ; maxAdjacent ( arr , N ) ; } }
Count 1 s present in a range of indices [ L , R ] in a given array | C # program to implement the above approach ; Function to find the size of the array if the array initially contains a single element ; Base case ; P / 2 -> findSize ( N / 2 ) P % 2 -> 1 P / 2 -> findSize ( N / 2 ) ; Function to return the count of 1 s in the range [ L , R ] ; Base Case ; PART 1 -> N / 2 [ 1 , Siz_M ] ; Update the right end point of the range to min ( Siz_M , R ) ; PART 2 -> N % 2 [ SizM + 1 , Siz_M + 1 ] ; PART 3 -> N / 2 [ SizM + 2 , 2 * Siz_M - 1 ] Same as PART 1 Property of Symmetricity Shift the coordinates according to PART 1 Subtract ( Siz_M + 1 ) from both L , R ; Driver code ; Input ; Counts the number of 1 's in  the range [L, R]
using System ; class GFG { static int findSize ( int N ) { if ( N == 0 ) return 1 ; if ( N == 1 ) return 1 ; int Size = 2 * findSize ( N / 2 ) + 1 ; return Size ; } static int CountOnes ( int N , int L , int R ) { if ( L > R ) { return 0 ; } if ( N <= 1 ) { return N ; } int ret = 0 ; int M = N / 2 ; int Siz_M = findSize ( M ) ; if ( L <= Siz_M ) { ret += CountOnes ( N / 2 , L , Math . Min ( Siz_M , R ) ) ; } if ( L <= Siz_M + 1 && Siz_M + 1 <= R ) { ret += N % 2 ; } if ( Siz_M + 1 < R ) { ret += CountOnes ( N / 2 , Math . Max ( 1 , L - Siz_M - 1 ) , R - Siz_M - 1 ) ; } return ret ; } static void Main ( ) { int N = 7 , L = 2 , R = 5 ; Console . WriteLine ( CountOnes ( N , L , R ) ) ; } }
Find the pair ( a , b ) with minimum LCM such that their sum is equal to N | C # program for the above approach ; Function to check if number is prime or not ; As 1 is neither prime nor composite return false ; Check if it is divided by any number then it is not prime , return false ; Check if n is not divided by any number then it is prime and hence return true ; Function to find the pair ( a , b ) such that sum is N & LCM is minimum ; Check if the number is prime ; Now , if it is not prime then find the least divisior ; Check if divides n then it is a factor ; Required output is a = n / i & b = n / i * ( n - 1 ) ; Driver Code ; Function call
using System ; class GFG { static bool prime ( int n ) { if ( n == 1 ) return false ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static void minDivisior ( int n ) { if ( prime ( n ) ) { Console . Write ( 1 + " ▁ " + ( n - 1 ) ) ; } else { for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { Console . Write ( n / i + " ▁ " + ( n / i * ( i - 1 ) ) ) ; break ; } } } } public static void Main ( String [ ] args ) { int N = 4 ; minDivisior ( N ) ; } }
Find Landau 's function for a given number N | C # program for the above approach ; To store Landau 's function of the number ; Function to return gcd of 2 numbers ; Function to return LCM of two numbers ; Function to find max lcm value among all representations of n ; Calculate Landau 's value ; Recursive function to find different ways in which n can be written as sum of atleast one positive integers ; Check if sum becomes n , consider this representation ; Start from previous element in the representation till n ; Include current element from representation ; Call function again with reduced sum ; Backtrack - remove current element from representation ; Function to find the Landau 's function ; Using recurrence find different ways in which n can be written as a sum of atleast one + ve integers ; Print the result ; Driver Code ; Given N ; Function call
using System ; using System . Collections . Generic ; class GFG { static int Landau = int . MinValue ; static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int lcm ( int a , int b ) { return ( a * b ) / gcd ( a , b ) ; } static void findLCM ( List < int > arr ) { int nth_lcm = arr [ 0 ] ; for ( int i = 1 ; i < arr . Count ; i ++ ) nth_lcm = lcm ( nth_lcm , arr [ i ] ) ; Landau = Math . Max ( Landau , nth_lcm ) ; } static void findWays ( List < int > arr , int i , int n ) { if ( n == 0 ) findLCM ( arr ) ; for ( int j = i ; j <= n ; j ++ ) { arr . Add ( j ) ; findWays ( arr , j , n - j ) ; arr . RemoveAt ( arr . Count - 1 ) ; } } static void Landau_function ( int n ) { List < int > arr = new List < int > ( ) ; findWays ( arr , 1 , n ) ; Console . Write ( Landau ) ; } public static void Main ( String [ ] args ) { int N = 4 ; Landau_function ( N ) ; } }
Check if the remainder of N | C # implementation to check the following expression for an integer N is valid or not ; Function to check if a number holds the condition ( N - 1 ) ! % N = N - 1 ; Corner cases ; Number divisible by 2 or 3 are not prime ; Iterate from 5 and keep checking for prime ; Function to check the expression for the value N ; Driver code
using System ; class GFG { static bool isPrime ( int n ) { if ( n == 1 ) return true ; 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 void checkExpression ( int n ) { if ( isPrime ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } public static void Main ( ) { int N = 3 ; checkExpression ( N ) ; } }
Check if it is possible to split given Array into K odd | C # implementation to check if it is possible to split array into K subsets with odd sum ; Function to check if array can be split in required K subsets ; Store count of odd numbers ; Check if element is odd ; Check if split is possible ; Driver code
using System ; class GFG { static bool checkArray ( int n , int k , int [ ] arr ) { int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) cnt += 1 ; } if ( cnt >= k && cnt % 2 == k % 2 ) return true ; else return false ; } public static void Main ( string [ ] args ) { int [ ] arr = { 1 , 3 , 4 , 7 , 5 , 3 , 1 } ; int n = arr . Length ; int k = 4 ; if ( checkArray ( n , k , arr ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Sum of division of the possible pairs for the given Array | C # implementation to compute the sum of division of all the possible pairs for the given array ; Function to compute the sum ; Counting frequency of each term and finding maximum among it ; Making cumulative frequency ; Taking the ceil value ; nos . in [ ( n - 0.5 ) X , ( n + 0.5 ) X ) range will add n to the ans ; Return the readonly result ; Driver code
using System ; class GFG { static long func ( int [ ] arr , int n ) { double ans = 0 ; int maxx = 0 ; double [ ] freq = new double [ 100005 ] ; int temp ; for ( int i = 0 ; i < n ; i ++ ) { temp = arr [ i ] ; freq [ temp ] ++ ; maxx = Math . Max ( maxx , temp ) ; } for ( int i = 1 ; i <= maxx ; i ++ ) { freq [ i ] += freq [ i - 1 ] ; } for ( int i = 1 ; i <= maxx ; i ++ ) { if ( freq [ i ] != 0 ) { double j ; double cur = Math . Ceiling ( 0.5 * i ) - 1.0 ; for ( j = 1.5 ; ; j ++ ) { int val = Math . Min ( maxx , ( int ) ( Math . Ceiling ( i * j ) - 1.0 ) ) ; int times = ( int ) ( freq [ i ] - freq [ i - 1 ] ) , con = ( int ) ( j - 0.5 ) ; ans += times * con * ( freq [ ( int ) val ] - freq [ ( int ) cur ] ) ; cur = val ; if ( val == maxx ) break ; } } } return ( long ) ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 } ; int n = arr . Length ; Console . Write ( func ( arr , n ) + " STRNEWLINE " ) ; } }
Count of elements to be inserted to make Array sum twice the XOR of Array | C # program to find the count of elements to be inserted to make Array sum twice the XOR of Array ; Function to find the minimum number of elements that need to be inserted such that the sum of the elements of the array is twice the XOR of the array ; Variable to store the Xor of all the elements ; Variable to store the sum of all elements ; Loop to find the Xor and the sum of the array ; If sum = 2 * Xor ; No need to insert more elements ; We insert one more element which is Sum ; We insert two more elements Sum + Xor and Xor . ; Print the number of elements inserted in the array ; Print the elements that are inserted in the array ; Driver code
using System ; class GFG { static void insert_element ( int [ ] a , int n ) { int Xor = 0 ; int Sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { Xor ^= a [ i ] ; Sum += a [ i ] ; } if ( Sum == 2 * Xor ) { Console . Write ( "0" ) ; return ; } if ( Xor == 0 ) { Console . Write ( "1" + ' STRNEWLINE ' ) ; Console . Write ( Sum ) ; return ; } int num1 = Sum + Xor ; int num2 = Xor ; Console . Write ( "2" ) ; Console . Write ( num1 + " ▁ " + num2 ) ; } public static void Main ( string [ ] args ) { int [ ] a = { 1 , 2 , 3 } ; int n = a . Length ; insert_element ( a , n ) ; } }
Check if roots of a Quadratic Equation are reciprocal of each other or not | C # program to check if roots of a quadratic equation are reciprocal of each other or not ; Function to check if the roots of a quadratic equation are reciprocal of each other or not ; Driver code
using System ; class GFG { static void checkSolution ( int a , int b , int c ) { if ( a == c ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } public static void Main ( ) { int a = 2 , b = 0 , c = 2 ; checkSolution ( a , b , c ) ; } }
Sunny Number | C # program for the above approach ; Function check whether x is a perfect square or not ; Find floating point value of square root of x . ; If square root is an integer ; Function to check sunny number ; Check if ( N + 1 ) is a perfect square or not ; If ( N + 1 ) is not a perfect square ; Driver code ; Given Number ; Function call
using System ; class GFG { static bool isPerfectSquare ( double x ) { double sr = Math . Sqrt ( x ) ; return ( ( sr - Math . Floor ( sr ) ) == 0 ) ; } static void checkSunnyNumber ( int N ) { if ( isPerfectSquare ( N + 1 ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } public static void Main ( String [ ] args ) { int N = 8 ; checkSunnyNumber ( N ) ; } }
Count the numbers which can convert N to 1 using given operation | C # program to count the numbers which can convert N to 1 using the given operation ; Function to count the numbers which can convert N to 1 using the given operation ; Iterate through all the integers ; Check if N can be converted to 1 ; Incrementing the count if it can be converted ; Driver code
using System ; class GFG { static int countValues ( int n ) { int answer = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { int k = n ; while ( k >= i ) { if ( k % i == 0 ) k /= i ; else k -= i ; } if ( k == 1 ) answer ++ ; } return answer ; } public static void Main ( ) { int N = 6 ; Console . Write ( countValues ( N ) ) ; } }
Find K numbers with sum equal to N and sum of their squares maximized | C # program to find K numbers with sum equal to N and the sum of their squares maximized ; Function that prints the required K numbers ; Print 1 , K - 1 times ; Print ( N - K + 1 ) ; Driver code
using System ; class GFG { static void printKNumbers ( int N , int K ) { for ( int i = 0 ; i < K - 1 ; i ++ ) Console . Write ( 1 + " ▁ " ) ; Console . Write ( N - K + 1 ) ; } public static void Main ( String [ ] args ) { int N = 10 , K = 3 ; printKNumbers ( N , K ) ; } }
Print Nth Stepping or Autobiographical number | C # implementation to find N 'th stepping natural Number ; Function to find the Nth stepping natural number ; Declare the queue ; Enqueue 1 , 2 , ... , 9 in this order ; Perform K operation on queue ; Get the ith Stepping number ; Perform Dequeue from the Queue ; If x mod 10 is not equal to 0 ; then Enqueue 10 x + ( x mod 10 ) - 1 ; Enqueue 10 x + ( x mod 10 ) ; If x mod 10 is not equal to 9 ; then Enqueue 10 x + ( x mod 10 ) + 1 ; Return the dequeued number of the K - th operation as the Nth stepping number ; Driver Code ; initialise K
using System ; using System . Collections . Generic ; class GFG { static int NthSmallest ( int K ) { List < int > Q = new List < int > ( ) ; int x = 0 ; for ( int i = 1 ; i < 10 ; i ++ ) Q . Add ( i ) ; for ( int i = 1 ; i <= K ; i ++ ) { x = Q [ 0 ] ; Q . RemoveAt ( 0 ) ; if ( x % 10 != 0 ) { Q . Add ( x * 10 + x % 10 - 1 ) ; } Q . Add ( x * 10 + x % 10 ) ; if ( x % 10 != 9 ) { Q . Add ( x * 10 + x % 10 + 1 ) ; } } return x ; } public static void Main ( String [ ] args ) { int N = 16 ; Console . Write ( NthSmallest ( N ) ) ; } }
Least number to be added to or subtracted from N to make it a Perfect Square | C # implementation of the approach ; Function to return the Least number ; Get the perfect square before and after N ; Check which is nearest to N ; return the result ; Driver code
using System ; class GFG { static int nearest ( int n ) { int prevSquare = ( int ) Math . Sqrt ( n ) ; int nextSquare = prevSquare + 1 ; prevSquare = prevSquare * prevSquare ; nextSquare = nextSquare * nextSquare ; int ans = ( n - prevSquare ) < ( nextSquare - n ) ? ( prevSquare - n ) : ( nextSquare - n ) ; return ans ; } public static void Main ( string [ ] args ) { int n = 14 ; Console . WriteLine ( nearest ( n ) ) ; n = 16 ; Console . WriteLine ( nearest ( n ) ) ; n = 18 ; Console . WriteLine ( nearest ( n ) ) ; } }
Value of Pi ( Î ) up to 50 decimal places | C # program to calculate the value of pi up to n decimal places ; Function that prints the value of pi upto N decimal places ; Find value of pi upto using acos ( ) function ; Print value of pi upto N decimal places ; Driver Code ; Function that prints the value of pi
using System ; class GFG { static void printValueOfPi ( int N ) { double pi = 2 * Math . Acos ( 0.0 ) ; Console . WriteLine ( pi ) ; } public static void Main ( ) { int N = 4 ; printValueOfPi ( N ) ; } }
Invert the Kth most significant bit of N | C # implementation of the approach ; Function to convert decimal number n to its binary representation stored as an array [ ] arr ; Function to convert the number represented as a binary array [ ] arr into its decimal equivalent ; Function to return the updated integer after flipping the kth bit ; Number of bits in n ; Find the binary representation of n ; The number of bits in n are less than k ; Flip the kth bit ; Return the decimal equivalent of the number ; Driver code
using System ; class GFG { static void decBinary ( int [ ] arr , int n ) { int k = ( int ) ( Math . Log ( n ) / Math . Log ( 2 ) ) ; while ( n > 0 ) { arr [ k -- ] = n % 2 ; n /= 2 ; } } static int binaryDec ( int [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans += arr [ i ] << ( n - i - 1 ) ; return ans ; } static int getNum ( int n , int k ) { int l = ( int ) ( Math . Log ( n ) / Math . Log ( 2 ) ) + 1 ; int [ ] a = new int [ l ] ; decBinary ( a , n ) ; if ( k > l ) return n ; a [ k - 1 ] = ( a [ k - 1 ] == 0 ) ? 1 : 0 ; return binaryDec ( a , l ) ; } public static void Main ( String [ ] args ) { int n = 56 ; int k = 2 ; Console . WriteLine ( getNum ( n , k ) ) ; } }
Queries for the product of first N factorials | C # implementation of the approach ; Declare result array globally ; Function to precompute the product of factorials upto MAX ; Initialize base condition if n = 0 then factorial of 0 is equal to 1 and answer for n = 0 is 1 ; Iterate loop from 1 to MAX ; factorial ( i ) = factorial ( i - 1 ) * i ; Result for current n is equal to result [ i - 1 ] multiplied by the factorial of i ; Function to perform the queries ; Precomputing the result till MAX ; Perform queries ; Driver code
using System ; class GFG { static int MAX = 1000000 ; static int MOD = 10000007 ; static int [ ] result = new int [ MAX + 1 ] ; static int [ ] fact = new int [ MAX + 1 ] ; static void preCompute ( ) { fact [ 0 ] = 1 ; result [ 0 ] = 1 ; for ( int i = 1 ; i <= MAX ; i ++ ) { fact [ i ] = ( ( fact [ i - 1 ] % MOD ) * i ) % MOD ; result [ i ] = ( ( result [ i - 1 ] % MOD ) * ( fact [ i ] % MOD ) ) % MOD ; } } static void performQueries ( int [ ] q , int n ) { preCompute ( ) ; for ( int i = 0 ; i < n ; i ++ ) Console . WriteLine ( result [ q [ i ] ] ) ; } public static void Main ( String [ ] args ) { int [ ] q = { 4 , 5 } ; int n = q . Length ; performQueries ( q , n ) ; } }
Nth number in a set of multiples of A , B or C | C # program to find nth term divisible by a , b or c ; Function to return gcd of a and b ; Function to return the count of integers from the range [ 1 , num ] which are divisible by either a , b or c ; Calculate the number of terms divisible by a , b and c then remove the terms which are divisible by both ( a , b ) or ( b , c ) or ( c , a ) and then add the numbers which are divisible by a , b and c ; Function for binary search to find the nth term divisible by a , b or c ; Set low to 1 and high to LONG_MAX ; If the current term is less than n then we need to increase low to mid + 1 ; If current term is greater than equal to n then high = mid ; Driver code
using System ; class GFG { static long gcd ( long a , long b ) { if ( a == 0 ) { return b ; } return gcd ( b % a , a ) ; } static long divTermCount ( long a , long b , long c , long num ) { return ( ( num / a ) + ( num / b ) + ( num / c ) - ( num / ( ( a * b ) / gcd ( a , b ) ) ) - ( num / ( ( c * b ) / gcd ( c , b ) ) ) - ( num / ( ( a * c ) / gcd ( a , c ) ) ) + ( num / ( ( a * b * c ) / gcd ( gcd ( a , b ) , c ) ) ) ) ; } static long findNthTerm ( int a , int b , int c , long n ) { long low = 1 , high = long . MaxValue , mid ; while ( low < high ) { mid = low + ( high - low ) / 2 ; if ( divTermCount ( a , b , c , mid ) < n ) { low = mid + 1 ; } else { high = mid ; } } return low ; } public static void Main ( String [ ] args ) { int a = 2 , b = 3 , c = 5 , n = 100 ; Console . WriteLine ( findNthTerm ( a , b , c , n ) ) ; } }
Angle between 3 given vertices in a n | C # implementation of the approach ; Function that checks whether given angle can be created using any 3 sides ; Initialize x and y ; Calculate the number of vertices between i and j , j and k ; Calculate the angle subtended at the circumference ; Angle subtended at j can be found using the fact that the sum of angles of a triangle is equal to 180 degrees ; Driver code
using System ; class GFG { static double calculate_angle ( int n , int i , int j , int k ) { int x , y ; if ( i < j ) x = j - i ; else x = j + n - i ; if ( j < k ) y = k - j ; else y = k + n - j ; double ang1 = ( 180 * x ) / n ; double ang2 = ( 180 * y ) / n ; double ans = 180 - ang1 - ang2 ; return ans ; } public static void Main ( ) { int n = 5 ; int a1 = 1 ; int a2 = 2 ; int a3 = 5 ; Console . WriteLine ( ( int ) calculate_angle ( n , a1 , a2 , a3 ) ) ; } }
Loss when two items are sold at same price and same percentage profit / loss | C # implementation of above approach . ; Function that will find loss ; Driver Code ; Calling Function
class GFG { static void Loss ( int SP , int P ) { double loss = 0 ; loss = ( double ) ( 2 * P * P * SP ) / ( 100 * 100 - P * P ) ; System . Console . WriteLine ( " Loss ▁ = ▁ " + System . Math . Round ( loss , 3 ) ) ; } static void Main ( ) { int SP = 2400 , P = 30 ; Loss ( SP , P ) ; } }
Check for an array element that is co | C # implementation of the approach ; Stores smallest prime factor for every number ; Hash to store prime factors count ; Function to calculate SPF ( Smallest Prime Factor ) for every number till MAXN ; Marking smallest prime factor for every number to be itself ; Separately marking spf 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 to store the prime factors after dividing by the smallest prime factor at every step ; Storing the count of prime factors in hash ; Function that returns true if there are no common prime factors between x and other numbers of the array ; Checking whether it common prime factor with other numbers ; Function that returns true if there is an element in the array which is coprime with all the other elements of the array ; Using sieve for generating prime factors ; Checking the common prime factors with other numbers ; Driver code
using System ; class GFG { static int MAXN = 1000001 ; static int [ ] spf = new int [ MAXN ] ; static int [ ] hash1 = new int [ MAXN ] ; static void sieve ( ) { spf [ 1 ] = 1 ; for ( int i = 2 ; i < MAXN ; i ++ ) spf [ i ] = i ; for ( int i = 4 ; i < MAXN ; i += 2 ) spf [ i ] = 2 ; for ( int i = 3 ; i * i < MAXN ; i ++ ) { if ( spf [ i ] == i ) { for ( int j = i * i ; j < MAXN ; j += i ) if ( spf [ j ] == j ) spf [ j ] = i ; } } } static void getFactorization ( int x ) { int temp ; while ( x != 1 ) { temp = spf [ x ] ; if ( x % temp == 0 ) { hash1 [ spf [ x ] ] ++ ; x = x / spf [ x ] ; } while ( x % temp == 0 ) x = x / temp ; } } static bool check ( int x ) { int temp ; while ( x != 1 ) { temp = spf [ x ] ; if ( x % temp == 0 && hash1 [ temp ] > 1 ) return false ; while ( x % temp == 0 ) x = x / temp ; } return true ; } static bool hasValidNum ( int [ ] arr , int n ) { sieve ( ) ; for ( int i = 0 ; i < n ; i ++ ) getFactorization ( arr [ i ] ) ; for ( int i = 0 ; i < n ; i ++ ) if ( check ( arr [ i ] ) ) return true ; return false ; } static void Main ( ) { int [ ] arr = { 2 , 8 , 4 , 10 , 6 , 7 } ; int n = arr . Length ; if ( hasValidNum ( arr , n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Ways to Remove Edges from a Complete Graph to make Odd Edges | C # implementation of the approach ; Function to return the number of ways to remove edges from the graph so that odd number of edges are left in the graph ; Total number of edges ; Driver code
using System ; public class GFG { static int countWays ( int N ) { int E = ( N * ( N - 1 ) ) / 2 ; if ( N == 1 ) return 0 ; return ( int ) Math . Pow ( 2 , E - 1 ) ; } static public void Main ( ) { int N = 4 ; Console . WriteLine ( countWays ( N ) ) ; } }