codeparrot/xlcost-text-to-code huggingface dataset:
Length of Longest Prime Subsequence in an Array | C # program to find the length of longest Prime Subsequence in an Array ; Function to create Sieve to check primes ; False here indicates that it is not prime ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p , set them to non - prime ; Function to find the longest subsequence which contain all prime numbers ; Precompute N primes ; Find the length of longest prime subsequence ; Driver code ; Function call
using System ; class GFG { static readonly int N = 100005 ; static void SieveOfEratosthenes ( bool [ ] prime , int p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } static int longestPrimeSubsequence ( int [ ] arr , int n ) { bool [ ] prime = new bool [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) prime [ i ] = true ; SieveOfEratosthenes ( prime , N ) ; int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { answer ++ ; } } return answer ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 4 , 11 , 2 , 9 , 21 } ; int n = arr . Length ; Console . Write ( longestPrimeSubsequence ( arr , n ) + " STRNEWLINE " ) ; } }
Check if an Octal number is Even or Odd | C # code to check if a Octal number is Even or Odd ; Check if the number is odd or even ; Check if the last digit is either '0' , '2' , '4' , or '6' ; Driver code
using System ; public class GFG { static String even_or_odd ( String N ) { int len = N . Length ; if ( N [ len - 1 ] == '0' N [ len - 1 ] == '2' N [ len - 1 ] == '4' N [ len - 1 ] == '6' ) return ( " Even " ) ; else return ( " Odd " ) ; } public static void Main ( String [ ] args ) { String N = "735" ; Console . Write ( even_or_odd ( N ) ) ; } }
Runge | C # program to implement Runge Kutta method ; A sample differential equation " dy / dx ▁ = ▁ ( x ▁ - ▁ y ) /2" ; Finds value of y for a given x using step size h and initial value y0 at x0 . ; Count number of iterations using step size or step height h ; Iterate for number of iterations ; Apply Runge Kutta Formulas to find next value of y ; Update next value of y ; Update next value of x ; Driver Code
using System ; class GFG { static double dydx ( double x , double y ) { return ( x + y - 2 ) ; } static double rungeKutta ( double x0 , double y0 , double x , double h ) { int n = ( int ) ( ( x - x0 ) / h ) ; double k1 , k2 ; double y = y0 ; for ( int i = 1 ; i <= n ; i ++ ) { k1 = h * dydx ( x0 , y ) ; k2 = h * dydx ( x0 + 0.5 * h , y + 0.5 * k1 ) ; y = y + ( 1.0 / 6.0 ) * ( k1 + 2 * k2 ) ; x0 = x0 + h ; } return y ; } public static void Main ( string [ ] args ) { double x0 = 0 , y = 1 , x = 2 , h = 0.2 ; Console . WriteLine ( rungeKutta ( x0 , y , x , h ) ) ; } }
Count of Fibonacci pairs which satisfy the given equation | C # program to find the count of Fibonacci pairs ( x , y ) which satisfy the equation Ax + By = N ; Array to store the Fibonacci numbers ; Array to store the number of ordered pairs ; Function to find if a number is a perfect square ; Function that returns 1 if N is non - fibonacci number else 0 ; N is Fibinacci if one of 5 * n * n + 4 or 5 * n * n - 4 or both are perferct square ; Function to store the fibonacci numbers and their frequency in form a * x + b * y ; Storing the Fibonacci numbers ; For loop to find all the possible combinations of the Fibonacci numbers ; Finding the number of ordered pairs ; Driver code ; Find the ordered pair for every query
using System ; class GFG { static readonly int size = 10001 ; static long [ ] fib = new long [ 100010 ] ; static int [ ] freq = new int [ 100010 ] ; static bool isPerfectSquare ( int x ) { int s = ( int ) Math . Sqrt ( x ) ; return ( s * s == x ) ; } static int isFibonacci ( int n ) { if ( isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ) return 1 ; return 0 ; } static void compute ( int a , int b ) { for ( int i = 1 ; i < 100010 ; i ++ ) { fib [ i ] = isFibonacci ( i ) ; } for ( int x = 1 ; x < 100010 ; x ++ ) { for ( int y = 1 ; y < size ; y ++ ) { if ( fib [ x ] == 1 && fib [ y ] == 1 && a * x + b * y < 100010 ) { freq [ a * x + b * y ] ++ ; } } } } public static void Main ( String [ ] args ) { int Q = 2 , A = 5 , B = 10 ; compute ( A , B ) ; int [ ] arr = { 50 , 150 } ; for ( int i = 0 ; i < Q ; i ++ ) { Console . Write ( freq [ arr [ i ] ] + " ▁ " ) ; } } }
Maximise the sum of two Numbers using at most one swap between them | C # program to maximise the sum of two Numbers using at most one swap between them ; Function to maximize the sum by swapping only one digit ; Store digits of max ( n1 , n2 ) ; Store digits of min ( n1 , n2 ) ; If length of the two numbers are unequal ; Find the most significant number and the most significant index for swapping ; If both numbers are of equal length ; Fetch the index of current maximum digit present in both the arrays ; Compute the difference ; Find the most significant index and the most significant digit to be swapped ; Restore the new numbers ; Display the maximized sum ; Driver code
using System ; class GFG { static int MAX = 100 ; static int max_element ( int [ ] arr , int pos ) { int tmp = arr [ 0 ] ; int ind = 0 ; for ( int i = 1 ; i < pos ; i ++ ) { if ( tmp < arr [ i ] ) { tmp = arr [ i ] ; ind = i ; } } return ind ; } static void findMaxSum ( int n1 , int n2 ) { int [ ] arr1 = new int [ MAX ] ; int [ ] arr2 = new int [ MAX ] ; int l1 = 0 , l2 = 0 ; int max1 = Math . Max ( n1 , n2 ) ; int min1 = Math . Min ( n1 , n2 ) ; for ( int i = max1 ; i > 0 ; i /= 10 ) arr1 [ l1 ++ ] = ( i % 10 ) ; for ( int i = min1 ; i > 0 ; i /= 10 ) arr2 [ l2 ++ ] = ( i % 10 ) ; int f = 0 ; if ( l1 != l2 ) { int index = ( max_element ( arr2 , l2 ) ) ; for ( int i = l1 - 1 ; i > ( l2 - 1 ) ; i -- ) { if ( arr1 [ i ] < arr2 [ index ] ) { int tmp = arr1 [ i ] ; arr1 [ i ] = arr2 [ index ] ; arr2 [ index ] = tmp ; f = 1 ; break ; } } } if ( f != 1 ) { int index1 = 0 , index2 = 0 ; int diff1 = 0 , diff2 = 0 ; for ( int i = l2 - 1 ; i >= 0 ; i -- ) { index1 = ( max_element ( arr1 , i ) ) ; index2 = ( max_element ( arr2 , i ) ) ; diff1 = ( arr2 [ index2 ] - arr1 [ i ] ) ; diff2 = ( arr1 [ index1 ] - arr2 [ i ] ) ; if ( diff1 > 0 diff2 > 0 ) { if ( diff1 > diff2 ) { int tmp = arr1 [ i ] ; arr1 [ i ] = arr2 [ index2 ] ; arr2 [ index2 ] = tmp ; break ; } else if ( diff2 > diff1 ) { int tmp = arr1 [ index1 ] ; arr1 [ index1 ] = arr2 [ i ] ; arr2 [ i ] = tmp ; break ; } else if ( diff1 == diff2 ) { if ( index1 <= index2 ) { int tmp = arr1 [ index1 ] ; arr1 [ index1 ] = arr2 [ i ] ; arr2 [ i ] = tmp ; break ; } else if ( index2 <= index1 ) { int tmp = arr1 [ i ] ; arr1 [ i ] = arr2 [ index2 ] ; arr2 [ index2 ] = tmp ; break ; } } } } } int f_n1 = 0 , f_n2 = 0 ; for ( int i = l1 - 1 ; i >= 0 ; i -- ) { f_n1 = ( f_n1 * 10 ) + arr1 [ i ] ; f_n2 = ( f_n2 * 10 ) + arr2 [ i ] ; } Console . Write ( f_n1 + f_n2 ) ; } public static void Main ( string [ ] args ) { int N1 = 9987 ; int N2 = 123 ; findMaxSum ( N1 , N2 ) ; } }
Check if a number is divisible by 47 or not | C # program to check whether a number is divisible by 47 or not ; Function to check if the number is divisible by 47 or not ; While there are at least two digits ; Extracting the last ; Truncating the number ; Subtracting fourteen times the last digit to the remaining number ; Finally return if the two - digit number is divisible by 47 or not ; Driver Code
using System ; class GFG { static bool isDivisible ( int n ) { int d ; while ( n / 100 > 0 ) { d = n % 10 ; n /= 10 ; n = Math . Abs ( n - ( d * 14 ) ) ; } return ( n % 47 == 0 ) ; } public static void Main ( ) { int N = 59173 ; if ( isDivisible ( N ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Check if a HexaDecimal number is Even or Odd | C # code to check if a HexaDecimal number is Even or Odd ; Check if the number is odd or even ; check if the last digit is either '0' , '2' , '4' , '6' , '8' , ' A ' ( = 10 ) , ' C ' ( = 12 ) or ' E ' ( = 14 ) ; Driver code
using System ; public class GFG { static string even_or_odd ( string N ) { int len = N . Length ; if ( N [ len - 1 ] == '0' N [ len - 1 ] == '2' N [ len - 1 ] == '4' N [ len - 1 ] == '6' N [ len - 1 ] == '8' N [ len - 1 ] == ' A ' N [ len - 1 ] == ' C ' N [ len - 1 ] == ' E ' ) return ( " Even " ) ; else return ( " Odd " ) ; } static public void Main ( ) { string N = " AB3454D " ; Console . WriteLine ( even_or_odd ( N ) ) ; } }
Check if a number is divisible by 31 or not | C # program to check whether a number is divisible by 31 or not ; Function to check if the number is divisible by 31 or not ; While there are at least two digits ; Extracting the last ; Truncating the number ; Subtracting three times the last digit to the remaining number ; Finally return if the two - digit number is divisible by 31 or not ; Driver Code
using System ; class GFG { static bool isDivisible ( int n ) { int d ; while ( ( n / 100 ) > 0 ) { d = n % 10 ; n /= 10 ; n = Math . Abs ( n - ( d * 3 ) ) ; } return ( n % 31 == 0 ) ; } public static void Main ( String [ ] args ) { int N = 1922 ; if ( isDivisible ( N ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Check if the number is divisible 43 or not | C # program to check whether a number is divisible by 43 or not ; Function to check if the number is divisible by 43 or not ; While there are at least two digits ; Extracting the last ; Truncating the number ; adding thirteen times the last digit to the remaining number ; Finally return if the two - digit number is divisible by 43 or not ; Driver Code
using System ; class GFG { static bool isDivisible ( int n ) { int d ; while ( n / 100 > 0 ) { d = n % 10 ; n /= 10 ; n = Math . Abs ( n + ( d * 13 ) ) ; } return ( n % 43 == 0 ) ; } public static void Main ( ) { int N = 2795 ; if ( isDivisible ( N ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Find the next Non | C # implementation of the approach ; Function to check if a number is perfect square ; Function to check if a number is Fibinacci Number ; N is Fibinacci if either ( 5 * N * N + 4 ) , ( 5 * N * N - 4 ) or both is a perferct square ; Function to find the next Non - Fibinacci Number ; Case 1 If N <= 3 , then 4 will be next Non - Fibinacci Number ; Case 2 If N + 1 is Fibinacci , then N + 2 will be next Non - Fibinacci Number ; If N + 1 is Non - Fibinacci , then N + 2 will be next Non - Fibinacci Number ; 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 int nextNonFibonacci ( int N ) { if ( N <= 3 ) return 4 ; if ( isFibonacci ( N + 1 ) ) return N + 2 ; else return N + 1 ; } public static void Main ( String [ ] args ) { int N = 3 ; Console . Write ( nextNonFibonacci ( N ) + " STRNEWLINE " ) ; N = 5 ; Console . Write ( nextNonFibonacci ( N ) + " STRNEWLINE " ) ; N = 7 ; Console . Write ( nextNonFibonacci ( N ) + " STRNEWLINE " ) ; } }
Represent K ^ N as the sum of exactly N numbers | C # program to represent K ^ N as the sum of exactly N numbers ; Function to print N numbers whose sum is a power of K ; Printing K ^ 1 ; Loop to print the difference of powers from K ^ 2 ; Driver code
using System ; class GFG { static void print ( int n , int k ) { Console . Write ( k + " ▁ " ) ; for ( int i = 2 ; i <= n ; i ++ ) { int x = ( int ) ( Math . Pow ( k , i ) - Math . Pow ( k , i - 1 ) ) ; Console . Write ( x + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int N = 3 , K = 4 ; print ( N , K ) ; } }
Check if the given number is divisible by 71 or not | C # program to check whether a number is divisible by 71 or not ; Function to check if the number is divisible by 71 or not ; While there are at least two digits ; Extracting the last ; Truncating the number ; Subtracting fourteen times the last digit to the remaining number ; Finally return if the two - digit number is divisible by 71 or not ; Driver Code
using System ; class GFG { static bool isDivisible ( int n ) { int d ; while ( n / 100 > 0 ) { d = n % 10 ; n /= 10 ; n = Math . Abs ( n - ( d * 7 ) ) ; } return ( n % 71 == 0 ) ; } public static void Main ( ) { int N = 5041 ; if ( isDivisible ( N ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Count of prime digits of a Number which divides the number | C # program to count number of digits which is prime and also divides number ; Function to find the number of digits in number which divides the number and is also a prime number ; Only 2 , 3 , 5 and 7 are prime one - digit number ; Loop to compute all the digits of the number untill it is not equal to the zero ; Fetching each digit of the number ; Checking if digit is greater than 0 and can divides n and is prime too ; Driven Code
using System ; class GFG { static int countDigit ( int n ) { bool [ ] prime = new bool [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) prime [ i ] = false ; prime [ 2 ] = prime [ 3 ] = true ; prime [ 5 ] = prime [ 7 ] = true ; int temp = n , count = 0 ; while ( temp != 0 ) { int d = temp % 10 ; temp /= 10 ; if ( d > 0 && n % d == 0 && prime [ d ] == true ) count ++ ; } return count ; } public static void Main ( string [ ] args ) { int n = 1032 ; Console . WriteLine ( countDigit ( n ) ) ; } }
Bitwise Operations on Digits of a Number | C # implementation of the approach ; Function to find the digits ; Function to Find OR of all digits of a number ; Find OR of all digits ; return OR of digits ; Function to Find AND of all digits of a number ; Find AND of all digits ; return AND of digits ; Function to Find XOR of all digits of a number ; Find XOR of all digits ; return XOR of digits ; Driver code ; Find and store all digits ; Find XOR of digits ; Find OR of digits ; Find AND of digits ; Driver code
using System ; class GFG { static int [ ] digit = new int [ 100000 ] ; static int findDigits ( int n ) { int count = 0 ; while ( n != 0 ) { digit [ count ] = n % 10 ; n = n / 10 ; ++ count ; } return count ; } static int OR_of_Digits ( int n , int count ) { int ans = 0 ; for ( int i = 0 ; i < count ; i ++ ) { ans = ans | digit [ i ] ; } return ans ; } static int AND_of_Digits ( int n , int count ) { int ans = 0 ; for ( int i = 0 ; i < count ; i ++ ) { ans = ans & digit [ i ] ; } return ans ; } static int XOR_of_Digits ( int n , int count ) { int ans = 0 ; for ( int i = 0 ; i < count ; i ++ ) { ans = ans ^ digit [ i ] ; } return ans ; } static void bitwise_operation ( int N ) { int countOfDigit = findDigits ( N ) ; Console . Write ( " XOR ▁ = ▁ " + XOR_of_Digits ( N , countOfDigit ) + " STRNEWLINE " ) ; Console . Write ( " OR ▁ = ▁ " + OR_of_Digits ( N , countOfDigit ) + " STRNEWLINE " ) ; Console . Write ( " AND ▁ = ▁ " + AND_of_Digits ( N , countOfDigit ) + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int N = 123456 ; bitwise_operation ( N ) ; } }
Length of longest subarray with product greater than or equal to 0 | C # implementation of the above approach ; Function that count the length of longest subarray with product greater than or equals to zero ; If product is greater than zero , return array size ; Traverse the array and if any negative element found then update the length of longest subarray with the length of left and right subarray ; Driver Code
using System ; class GFG { static int maxLength ( int [ ] arr , int N ) { int product = 1 , len = 0 ; for ( int i = 0 ; i < N ; i ++ ) { product *= arr [ i ] ; } if ( product >= 0 ) { return N ; } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < 0 ) { len = Math . Max ( len , Math . Max ( N - i - 1 , i ) ) ; } } return len ; } public static void Main ( ) { int [ ] arr = { - 1 , 1 , 1 , - 2 , 3 , 2 , - 1 } ; int N = arr . Length ; Console . WriteLine ( maxLength ( arr , N ) ) ; } }
Print a pair of numbers with the given Sum and Product | C # program to find any pair which has sum S and product P . ; Prints roots of quadratic equation ax * 2 + bx + c = 0 ; calculating the sq root value for b * b - 4 * a * c ; Finding the roots ; Check if the roots are valid or not ; Finding the roots ; Check if the roots are valid or not ; when d < 0 ; No such pair exists in this case ; Driver code
using System ; public class GFG { static void findRoots ( int b , int c ) { int a = 1 ; int d = b * b - 4 * a * c ; double sqrt_val = Math . Sqrt ( Math . Abs ( d ) ) ; if ( d > 0 ) { double x = - b + sqrt_val ; double y = - b - sqrt_val ; int root1 = ( int ) ( x ) / ( 2 * a ) ; int root2 = ( int ) ( y ) / ( 2 * a ) ; if ( root1 + root2 == - 1 * b && root1 * root2 == c ) Console . Write ( root1 + " , ▁ " + root2 ) ; else Console . Write ( - 1 ) ; } else if ( d == 0 ) { int root = - b / ( 2 * a ) ; if ( root + root == - 1 * b && root * root == c ) Console . Write ( root + " , ▁ " + root ) ; else Console . Write ( - 1 ) ; } else { Console . Write ( - 1 ) ; } Console . WriteLine ( ) ; } public static void Main ( string [ ] args ) { int S = 5 , P = 6 ; findRoots ( - S , P ) ; S = 5 ; P = 9 ; findRoots ( - S , P ) ; } }
Print N numbers such that their product is a Perfect Cube | C # program to find N numbers such that their product is a perfect cube ; Function to find the N numbers such that their product is a perfect cube ; Loop to traverse each number from 1 to N ; Print the cube of i as the ith term of the output ; Driver Code ; Function Call
using System ; class GFG { static void findNumbers ( int N ) { int i = 1 ; while ( i <= N ) { Console . Write ( ( i * i * i ) + " ▁ " ) ; i ++ ; } } public static void Main ( string [ ] args ) { int N = 4 ; findNumbers ( N ) ; } }
Sum of all proper divisors from 1 to N | C # implementation to find sum of all proper divisor of number up to N ; Utility function to find sum of all proper divisor of number up to N ; Loop to iterate over all the numbers from 1 to N ; Find all divisors of i and add them ; Subtracting ' i ' so that the number itself is not included ; Driver Code
using System ; class GFG { static int properDivisorSum ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; ++ i ) { for ( int j = 1 ; j * j <= i ; ++ j ) { if ( i % j == 0 ) { if ( i / j == j ) sum += j ; else sum += j + i / j ; } } sum = sum - i ; } return sum ; } public static void Main ( string [ ] args ) { int n = 4 ; Console . WriteLine ( properDivisorSum ( n ) ) ; n = 5 ; Console . WriteLine ( properDivisorSum ( n ) ) ; } }
Sum of all proper divisors from 1 to N | Utility function to find sum of all proper divisor of number up to N ; Loop to find the proper divisor of every number from 1 to N ; Driver Code
using System ; class GFG { static int properDivisorSum ( int n ) { int sum = 0 ; int i ; for ( i = 1 ; i <= n ; ++ i ) sum += ( n / i ) * i ; return sum - n * ( n + 1 ) / 2 ; } public static void Main ( String [ ] args ) { int n = 4 ; Console . WriteLine ( properDivisorSum ( n ) ) ; n = 5 ; Console . WriteLine ( properDivisorSum ( n ) ) ; } }
Minimum change in given value so that it lies in all given Ranges | C # implementation find the minimum difference in the number D such that D is inside of every range ; Function to find the minimum difference in the number D such that D is inside of every range ; Loop to find the common range out of the given array of ranges . ; Storing the start and end index ; Sorting the range ; Finding the maximum starting value of common segment ; Finding the minimum ending value of common segment ; If there is no common segment ; If the given number is between the computed common range . ; Finding the minimum distance ; Driver Code ; Given array of ranges
using System ; class GFG { static void findMinimumOperation ( int n , int d , int [ , ] arrays ) { int cnt = 0 ; int first = int . MinValue , end = int . MaxValue ; while ( n > 0 ) { int [ ] arr = { arrays [ cnt , 0 ] , arrays [ cnt , 1 ] } ; Array . Sort ( arr ) ; first = Math . Max ( first , arr [ 0 ] ) ; end = Math . Min ( end , arr [ 1 ] ) ; cnt ++ ; n -- ; } if ( first > end ) Console . Write ( " - 1" ) ; else { if ( d >= first && d <= end ) { Console . Write ( "0" ) ; } else Console . Write ( Math . Min ( Math . Abs ( first - d ) , Math . Abs ( d - end ) ) ) ; } } public static void Main ( String [ ] args ) { int n = 3 , d = 3 ; int [ , ] arrays = { { 0 , 7 } , { 2 , 14 } , { 4 , 6 } } ; findMinimumOperation ( n , d , arrays ) ; } }
Number of factors of very large number N modulo M where M is any prime number | C # implementation to find the Number of factors of very large number N modulo M ; Function for modular multiplication ; Function to find the number of factors of large Number N ; Count the number of times 2 divides the number N ; Condition to check if 2 divides it ; Check for all the possible numbers that can divide it ; Loop to check the number of times prime number i divides it ; Condition to check if prime number i divides it ; Condition to check if N at the end is a prime number . ; Driver Code
using System ; class GFG { static long mod = 1000000007L ; static long mult ( long a , long b ) { return ( ( a % mod ) * ( b % mod ) ) % mod ; } static long calculate_factors ( long n ) { long ans , cnt ; cnt = 0 ; ans = 1 ; while ( n % 2 == 0 ) { cnt ++ ; n = n / 2 ; } if ( cnt % 2 == 1 ) { ans = mult ( ans , ( cnt + 1 ) ) ; } for ( int i = 3 ; i <= Math . Sqrt ( n ) ; i += 2 ) { cnt = 0 ; while ( n % i == 0 ) { cnt ++ ; n = n / i ; } if ( cnt % 2 == 1 ) { ans = mult ( ans , ( cnt + 1 ) ) ; } } if ( n > 2 ) { ans = mult ( ans , ( 2 ) ) ; } return ans % mod ; } public static void Main ( String [ ] args ) { long n = 193748576239475639L ; mod = 17 ; Console . Write ( calculate_factors ( n ) + " STRNEWLINE " ) ; } }
Maximum value of B less than A such that A ^ B = A + B | Function to find the maximum value of B such that A ^ B = A + B ; Binary Representation of A ; Loop to find the negation of the integer A ; output ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void maxValue ( int a ) { String c = Convert . ToString ( a , 2 ) ; String b = " " ; for ( int i = 0 ; i < c . Length ; i ++ ) { if ( ( c [ i ] - '0' ) == 1 ) b += '0' ; else b += '1' ; } Console . Write ( Convert . ToInt32 ( b , 2 ) ) ; } public static void Main ( String [ ] args ) { int a = 4 ; maxValue ( a ) ; } }
Print all possible pair with prime XOR in the Array | C # implementation of the above approach ; Function for Sieve of Eratosthenes ; If i is prime , then make all multiples of i false ; Function to print all Pairs whose XOR is prime ; if A [ i ] ^ A [ j ] is prime , then print this pair ; Driver Code ; Generate all the prime number ; Function Call
using System ; class GFG { static int sz = ( int ) 1e5 ; static bool [ ] isPrime = new bool [ sz + 1 ] ; static void generatePrime ( ) { int i , j ; for ( i = 2 ; i <= sz ; i ++ ) isPrime [ i ] = true ; for ( i = 2 ; i * i <= sz ; i ++ ) { if ( isPrime [ i ] ) { for ( j = i * i ; j < sz ; j += i ) { isPrime [ j ] = false ; } } } } static void Pair_of_PrimeXor ( int [ ] A , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( isPrime [ ( A [ i ] ^ A [ j ] ) ] ) { Console . Write ( " ( " + A [ i ] + " , ▁ " + A [ j ] + " ) ▁ " ) ; } } } } public static void Main ( String [ ] args ) { int [ ] A = { 1 , 3 , 6 , 11 } ; int n = A . Length ; generatePrime ( ) ; Pair_of_PrimeXor ( A , n ) ; } }