codeparrot/xlcost-text-to-code huggingface dataset:
Check n ^ 2 | C # program to find n ^ 2 - m ^ 2 is prime or not . ; Check if a number is prime or not ; run a loop upto square of given number ; Check if n ^ 2 - m ^ 2 is prime ; Driver code
using System ; class GFG { static bool isprime ( int x ) { for ( int i = 2 ; i * i <= x ; i ++ ) if ( x % i == 0 ) return false ; return true ; } static bool isNSqMinusnMSqPrime ( int m , int n ) { if ( n - m == 1 && isprime ( m + n ) ) return true ; else return false ; } public static void Main ( ) { int m = 13 , n = 16 ; if ( isNSqMinusnMSqPrime ( m , n ) ) Console . Write ( " YES " ) ; else Console . Write ( " NO " ) ; } }
Find ' N ' number of solutions with the given inequality equations | C # implementation of above approach ; Function to calculate all the solutions ; there is no solutions ; print first element as y - n + 1 ; print rest n - 1 elements as 1 ; Driver code ; initialize the number of elements and the value of x an y
using System ; class GFG { static void findsolution ( long n , long x , long y ) { if ( ( y - n + 1 ) * ( y - n + 1 ) + n - 1 < x y < n ) { Console . WriteLine ( " No ▁ solution " ) ; return ; } Console . WriteLine ( y - n + 1 ) ; while ( n -- > 1 ) Console . WriteLine ( "1" ) ; } static public void Main ( ) { long n , x , y ; n = 5 ; x = 15 ; y = 15 ; findsolution ( n , x , y ) ; } }
Number of different positions where a person can stand | C # implementation of above approach ; Function to find the position ; Driver code
using System ; class GFG { static int findPosition ( int n , int f , int b ) { return n - Math . Max ( f + 1 , n - b ) + 1 ; } public static void Main ( ) { int n = 5 , f = 2 , b = 3 ; Console . WriteLine ( findPosition ( n , f , b ) ) ; } }
Program for n | C # program to find the nth odd number ; Function to find the nth odd number ; Driver code
using System ; class GFG { static int nthOdd ( int n ) { return ( 2 * n - 1 ) ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( nthOdd ( n ) ) ; } }
Program for n | C # program to find the nth EVEN number ; Function to find the nth odd number ; Driver code
using System ; class GFG { static int nthEven ( int n ) { return ( 2 * n ) ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( nthEven ( n ) ) ; } }
Program to find the Nth Harmonic Number | C # program to find N - th Harmonic Number ; Function to find N - th Harmonic Number ; H1 = 1 ; loop to apply the forumula Hn = H1 + H2 + H3 ... + Hn - 1 + Hn - 1 + 1 / n ; Driver Code
using System ; class GFG { static double nthHarmonic ( int N ) { float harmonic = 1 ; for ( int i = 2 ; i <= N ; i ++ ) { harmonic += ( float ) 1 / i ; } return harmonic ; } static public void Main ( ) { int N = 8 ; Console . Write ( nthHarmonic ( N ) ) ; } }
Program to find Nth term of series 0 , 7 , 18 , 33 , 51 , 75 , 102 , 133 , ... . . | C # program to find the N - th term of the series : 0 , 7 , 18 , 33 , 51 , 75 , 102 , ... . . ; calculate Nth term of series ; Driver code
using System ; class GFG { static int nthTerm ( int n ) { return 2 * ( int ) Math . Pow ( n , 2 ) + n - 3 ; } public static void Main ( ) { int N = 4 ; Console . Write ( nthTerm ( N ) ) ; } }
Program to find Nth term of series 0 , 10 , 30 , 60 , 99 , 150 , 210 , 280. ... ... ... . | C # program to find the N - th term of the series : 0 , 10 , 30 , 60 , 99 , 150 , 210 , ... . . ; calculate Nth term of series ; Driver code
using System ; class GFG { static int nthTerm ( int n ) { return 5 * ( int ) Math . Pow ( n , 2 ) - 5 * n ; } public static void Main ( ) { int N = 4 ; Console . Write ( nthTerm ( N ) ) ; } }
Program to find Nth term of series 2 , 12 , 28 , 50 , 77 , 112 , 152 , 198 , ... . . | C # program to find the N - th term of the series : 2 , 12 , 28 , 50 , 77 , 112 , 152 , 198 , ... . . ; calculate Nth term of series ; Driver Code
using System ; class GFG { static int nthTerm ( int n ) { return 3 * ( int ) Math . Pow ( n , 2 ) + n - 2 ; } public static void Main ( ) { int N = 4 ; Console . Write ( nthTerm ( N ) ) ; } }
Program to find Nth term of series 4 , 14 , 28 , 46 , 68 , 94 , 124 , 158 , ... . . | C # program to find the N - th term of the series : 4 , 14 , 28 , 46 , 68 , 94 , 124 , 158 , ... . . ; calculate Nth term of series ; Driver Code
using System ; class GFG { static int nthTerm ( int n ) { return 2 * ( int ) Math . Pow ( n , 2 ) + 4 * n - 2 ; } public static void Main ( ) { int N = 4 ; Console . Write ( nthTerm ( N ) ) ; } }
Program to find Nth term of series 0 , 11 , 28 , 51 , 79 , 115 , 156 , 203 , ... . | C # program to find the N - th term of the series : 0 , 11 , 28 , 51 , 79 , 115 , 156 , 203. . ... ; calculate Nth term of series ; Driver code
using System ; class GFG { static int nthTerm ( int n ) { return 3 * ( int ) Math . Pow ( n , 2 ) + 2 * n - 5 ; } public static void Main ( ) { int N = 4 ; Console . WriteLine ( nthTerm ( N ) ) ; } }
Program to find Nth term of series 0 , 9 , 22 , 39 , 60 , 85 , 114 , 147 , ... . . | C # program to find the N - th term of the series : 0 , 9 , 22 , 39 , 60 , 85 , 114 , 147. . ... ; calculate Nth term of series ; Driver code
using System ; class GFG { static int nthTerm ( int n ) { return 2 * ( int ) Math . Pow ( n , 2 ) + 3 * n - 5 ; } public static void Main ( ) { int N = 4 ; Console . WriteLine ( nthTerm ( N ) ) ; } }
Program to find Nth term of series 3 , 12 , 29 , 54 , 86 , 128 , 177 , 234 , ... . . | C # program to find the N - th term of the series : 3 , 12 , 29 , 54 , 86 , 128 , 177 , 234 , ... ; calculate Nth term of series ; Driver code
using System ; class GFG { static int nthTerm ( int n ) { return 4 * ( int ) Math . Pow ( n , 2 ) - 3 * n + 2 ; } public static void Main ( ) { int N = 4 ; Console . WriteLine ( nthTerm ( N ) ) ; } }
Find other two sides and angles of a right angle triangle | C # program to print all sides and angles of right angle triangle given one side ; Function to find angle A Angle in front of side a ; applied cosine rule ; convert into degrees ; Function to find angle B Angle in front of side b ; applied cosine rule ; convert into degrees and return ; Function to print all angles of the right angled triangle ; for calculate angle A ; for calculate angle B ; Function to find other two sides of the right angled triangle ; if n is odd ; case of n = 1 handled separately ; case of n = 2 handled separately ; Print angles of the triangle ; Driver Code
using System ; class GFG { static double PI = 3.1415926535 ; static double findAnglesA ( double a , double b , double c ) { double A = Math . Acos ( ( b * b + c * c - a * a ) / ( 2 * b * c ) ) ; return A * 180 / PI ; } static double findAnglesB ( double a , double b , double c ) { double B = Math . Acos ( ( a * a + c * c - b * b ) / ( 2 * a * c ) ) ; return B * 180 / PI ; } static void printAngles ( int a , int b , int c ) { double x = ( double ) a ; double y = ( double ) b ; double z = ( double ) c ; double A = findAnglesA ( x , y , z ) ; double B = findAnglesB ( x , y , z ) ; Console . WriteLine ( " Angles ▁ are ▁ A ▁ = ▁ " + A + " , ▁ B ▁ = ▁ " + B + " , ▁ C ▁ = ▁ " + 90 ) ; } static void printOtherSides ( int n ) { int b = 0 , c = 0 ; if ( ( n & 1 ) > 0 ) { if ( n == 1 ) Console . WriteLine ( - 1 ) ; else { b = ( n * n - 1 ) / 2 ; c = ( n * n + 1 ) / 2 ; Console . WriteLine ( " Side ▁ b ▁ = ▁ " + b + " , ▁ Side ▁ c ▁ = ▁ " + c ) ; } } else { if ( n == 2 ) Console . WriteLine ( - 1 ) ; else { b = n * n / 4 - 1 ; c = n * n / 4 + 1 ; Console . WriteLine ( " Side ▁ b ▁ = ▁ " + b + " , ▁ Side ▁ c ▁ = ▁ " + c ) ; } } printAngles ( n , b , c ) ; } public static void Main ( ) { int a = 12 ; printOtherSides ( a ) ; } }
Sum of the first N terms of the series 2 , 6 , 12 , 20 , 30. ... | C # program to find sum of first n terms ; Function to calculate the sum ; Driver code ; number of terms to be included in the sum ; find the Sn
using System ; class GFG { static int calculateSum ( int n ) { return n * ( n + 1 ) / 2 + n * ( n + 1 ) * ( 2 * n + 1 ) / 6 ; } public static void Main ( ) { int n = 3 ; Console . WriteLine ( " Sum ▁ = ▁ " + calculateSum ( n ) ) ; } }
Program to find the Nth term of the series 0 , 5 , 14 , 27 , 44 , ... ... . . | C # program to find N - th term of the series : 0 , 5 , 14 , 27 , 44 . . . ; Calculate Nth term of series ; Driver code
using System ; class GFG { static int nthTerm ( int n ) { return 2 * ( int ) Math . Pow ( n , 2 ) - n - 1 ; } static public void Main ( ) { int N = 4 ; Console . Write ( nthTerm ( N ) ) ; } }
Program to find the Nth term of the series 0 , 5 , 18 , 39 , 67 , 105 , 150 , 203 , ... | C # program to find the N - th term of the series : 0 , 5 , 18 , 39 , 67 , 105 , 150 , 203 , ; calculate Nth term of series ; Driver code
using System ; class GFG { static int nthTerm ( int n ) { return 4 * ( int ) Math . Pow ( n , 2 ) - 7 * n + 3 ; } static public void Main ( ) { int N = 4 ; Console . Write ( nthTerm ( N ) ) ; } }
Check whether a given Number is Power | C # program to find whether a number is power - isolated or not ; for 2 as prime factor ; for odd prime factor ; calculate product of powers and prime factors ; check result for power - isolation ; Driver code
using System ; class GFG { static void checkIfPowerIsolated ( int num ) { int input = num ; int count = 0 ; int [ ] factor = new int [ num + 1 ] ; if ( num % 2 == 0 ) { while ( num % 2 == 0 ) { ++ count ; num /= 2 ; } factor [ 2 ] = count ; } for ( int i = 3 ; i * i <= num ; i += 2 ) { count = 0 ; while ( num % i == 0 ) { ++ count ; num /= i ; } if ( count > 0 ) factor [ i ] = count ; } if ( num > 1 ) factor [ num ] = 1 ; int product = 1 ; for ( int i = 0 ; i < num + 1 ; i ++ ) { if ( factor [ i ] > 0 ) product = product * factor [ i ] * i ; } if ( product == input ) Console . Write ( " Power - isolated ▁ Integer STRNEWLINE " ) ; else Console . Write ( " Not ▁ a ▁ Power - isolated ▁ Integer STRNEWLINE " ) ; } static void Main ( ) { checkIfPowerIsolated ( 12 ) ; checkIfPowerIsolated ( 18 ) ; checkIfPowerIsolated ( 35 ) ; } }
Program to find the Nth term of the series 3 , 7 , 13 , 21 , 31. ... . | C # code to find the Nth term of given series . ; Function to calculate sum ; Return Nth term ; Driver Code ; declaration of number of terms ; Get the Nth term
using System ; class GFG { static long getNthTerm ( long N ) { return ( ( int ) Math . Pow ( N , 2 ) + N + 1 ) ; } static public void Main ( ) { long N = 11 ; Console . Write ( getNthTerm ( N ) ) ; } }
Sum of the numbers upto N that are divisible by 2 or 5 | C # implementation of above approach ; Function to find the sum ; sum2 is sum of numbers divisible by 2 ; sum5 is sum of number divisible by 5 ; sum10 of numbers divisible by 2 and 5 ; Driver code
using System ; class GFG { static long findSum ( int n ) { long sum2 , sum5 , sum10 ; sum2 = ( ( n / 2 ) * ( 4 + ( n / 2 - 1 ) * 2 ) ) / 2 ; sum5 = ( ( n / 5 ) * ( 10 + ( n / 5 - 1 ) * 5 ) ) / 2 ; sum10 = ( ( n / 10 ) * ( 20 + ( n / 10 - 1 ) * 10 ) ) / 2 ; return sum2 + sum5 - sum10 ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( findSum ( n ) ) ; } }
Find four factors of N with maximum product and sum equal to N | Set 3 | C # implementation of above approach ; Function to find primes ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Function to find factors ; run a loop upto square root of that number ; if the n is perfect square ; otherwise push it 's two divisors ; sort the divisors ; Function to find max product ; To store factors of ' n ' ; find factors ; if it is divisible by 4. ; if it is prime ; otherwise answer will be possible ; include last third factor ; nested loop to find other two factors ; Driver code ; function call
using System ; using System . Collections . Generic ; class GFG { static bool isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } static List < List < int > > v = new List < List < int > > ( ) ; static void factors ( int N ) { for ( int i = 2 ; i < N ; i ++ ) { for ( int j = 1 ; j * j <= i ; j ++ ) { if ( i % j == 0 ) { if ( i / j == j ) v [ i ] . Add ( j ) ; else { v [ i ] . Add ( j ) ; v [ i ] . Add ( i / j ) ; } } } v [ i ] . Sort ( ) ; } } static int product ( int n ) { v . Clear ( ) ; for ( int i = 0 ; i < n + 100 ; i ++ ) v . Add ( new List < int > ( ) ) ; factors ( n + 100 ) ; if ( n % 4 == 0 ) { int x = n / 4 ; x *= x ; return x * x ; } else { if ( isPrime ( n ) ) return - 1 ; else { int ans = - 1 ; if ( v [ n ] . Count > 2 ) { int fac = v [ n ] [ v [ n ] . Count - 3 ] ; for ( int i = v [ n ] . Count - 1 ; i >= 0 ; i -- ) { for ( int j = v [ n ] . Count - 1 ; j >= 0 ; j -- ) { if ( ( fac * 2 ) + ( v [ n ] [ j ] + v [ n ] [ i ] ) == n ) ans = Math . Max ( ans , fac * fac * v [ n ] [ j ] * v [ n ] [ i ] ) ; } } return ans ; } } } return 0 ; } public static void Main ( String [ ] args ) { int n = 24 ; Console . WriteLine ( product ( n ) ) ; } }
Ratio of mth and nth terms of an A . P . with given ratio of sums | C # code to calculate ratio ; function to calculate ratio of mth and nth term ; ratio will be tm / tn = ( 2 * m - 1 ) / ( 2 * n - 1 ) ; Driver code
using System ; class Nth { float CalculateRatio ( float m , float n ) { return ( 2 * m - 1 ) / ( 2 * n - 1 ) ; } public static void Main ( ) { float m = 6 , n = 2 ; Nth a = new Nth ( ) ; Console . WriteLine ( a . CalculateRatio ( m , n ) ) ; } }
Find the sum of n terms of the series 1 , 8 , 27 , 64 ... . | C # program to find the sum of n terms ; Function ot calculate the sum ; Return total sum ; Driver code
using System ; class GFG { static int calculateSum ( int n ) { return ( int ) Math . Pow ( n * ( n + 1 ) / 2 , 2 ) ; } public static void Main ( ) { int n = 4 ; Console . WriteLine ( calculateSum ( n ) ) ; } }
Sum of Digits in a ^ n till a single digit | C # program to find single digit sum of a ^ n . ; This function finds single digit sum of n . ; Returns single digit sum of a ^ n . We use modular exponentiation technique . ; Driver code
class GFG { static int digSum ( int n ) { if ( n == 0 ) return 0 ; return ( n % 9 == 0 ) ? 9 : ( n % 9 ) ; } static int powerDigitSum ( int a , int n ) { int res = 1 ; while ( n > 0 ) { if ( n % 2 == 1 ) { res = res * digSum ( a ) ; res = digSum ( res ) ; } a = digSum ( digSum ( a ) * digSum ( a ) ) ; n /= 2 ; } return res ; } static void Main ( ) { int a = 9 , n = 4 ; System . Console . WriteLine ( powerDigitSum ( a , n ) ) ; } }
Program to find total number of edges in a Complete Graph | C # implementation to find the number of edges in a complete graph ; Function to find the total number of edges in a complete graph with N vertices ; Driver Code
using System ; class GFG { static int totEdge ( int n ) { int result = 0 ; result = ( n * ( n - 1 ) ) / 2 ; return result ; } public static void Main ( ) { int n = 6 ; Console . Write ( totEdge ( n ) ) ; } }
Find minimum number of Log value needed to calculate Log upto N | C # program to find number of log values needed to calculate all the log values from 1 to N ; In this vector prime [ i ] will store true if prime [ i ] is prime , else store false ; Using sieve of Eratosthenes to find all prime upto N ; Function to find number of log values needed to calculate all the log values from 1 to N ; calculate primes upto N ; Driver code
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { static int MAX = 1000005 ; static List < Boolean > prime = new List < Boolean > ( MAX ) ; static void vecIni ( ) { for ( int i = 0 ; i < MAX ; i ++ ) { prime . Add ( true ) ; } } static void sieve ( int N ) { prime . Insert ( 0 , false ) ; prime . Insert ( 1 , false ) ; for ( int i = 2 ; i <= N ; i ++ ) { if ( prime [ i ] ) { for ( int j = 2 ; i * j <= N ; j ++ ) { prime . Insert ( i * j , false ) ; } } } } static int countLogNeeded ( int N ) { int count = 0 ; sieve ( N ) ; for ( int i = 1 ; i <= N ; i ++ ) { if ( prime [ i ] ) { count ++ ; } } return count ; } public static void Main ( ) { vecIni ( ) ; int N = 6 ; Console . Write ( countLogNeeded ( N ) ) ; } }
Program to find the count of coins of each type from the given ratio | C # implementation of above approach ; function to calculate coin . ; Converting each of them in rupees . As we are given totalRupees = 1800 ; Driver code
using System ; class GFG { static int coin ( int totalRupees , int X , int Y , int Z ) { float one = 0 , fifty = 0 , twentyfive = 0 , result = 0 , total = 0 ; one = X * 1 ; fifty = ( ( Y * 1 ) / 2 ) ; twentyfive = ( ( Z * 1 ) / 4 ) ; total = one + fifty + twentyfive ; result = ( ( totalRupees ) / total ) ; return ( int ) result ; } public static void Main ( ) { int totalRupees = 1800 ; int X = 1 , Y = 2 , Z = 4 ; int Rupees = coin ( totalRupees , X , Y , Z ) ; Console . WriteLine ( "1 ▁ rupess ▁ coins ▁ = ▁ " + Rupees * 1 ) ; Console . WriteLine ( "50 ▁ paisa ▁ coins ▁ = ▁ " + Rupees * 2 ) ; Console . WriteLine ( "25 ▁ paisa ▁ coins ▁ = ▁ " + Rupees * 4 ) ; } }
Find the sum of series 0. X + 0. XX + 0. XXX + ... upto k terms | C # program for sum of the series 0. x , 0. xx , 0. xxx , ... upto k terms ; function which return the sum of series ; Driver code
using System ; class GFG { static float sumOfSeries ( int x , int k ) { float y = ( float ) ( ( ( float ) ( x ) / 81 ) * ( 9 * k - 1 + Math . Pow ( 10 , ( - 1 ) * k ) ) ) ; return y ; } public static void Main ( ) { int x = 9 ; int k = 20 ; Console . Write ( sumOfSeries ( x , k ) ) ; } }
Find four factors of N with maximum product and sum equal to N | Set | C # program to find four factors of N with maximum product and sum equal to N ; Function to find factors and to print those four factors ; push all the factors in the container ; number of factors ; Initial maximum ; hash - array to mark the pairs ; form all the pair sums ; if the pair sum is less than n ; push in another container ; mark the sum with the elements formed ; mark in the map that v [ i ] + v [ j ] is present ; new size of all the pair sums ; iterate for all pair sum ; the required part ; if the required part is also present in pair sum ; find the elements with which the first pair is formed ; find the elements with which the second pair is formed ; check for previous maximum ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void findfactors ( int n ) { Dictionary < int , int > mpp = new Dictionary < int , int > ( ) ; List < int > v = new List < int > ( ) , v1 = new List < int > ( ) ; for ( int i = 1 ; i <= ( int ) Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v . Add ( i ) ; if ( i != ( n / i ) && i != 1 ) v . Add ( n / i ) ; } } int s = v . Count ; int maxi = - 1 ; int [ ] mp1_first = new int [ n + 5 ] ; int [ ] mp1_second = new int [ n + 5 ] ; for ( int i = 0 ; i < s ; i ++ ) { for ( int j = i ; j < s ; j ++ ) { if ( v [ i ] + v [ j ] < n ) { v1 . Add ( v [ i ] + v [ j ] ) ; mp1_first [ v [ i ] + v [ j ] ] = v [ i ] ; mp1_second [ v [ i ] + v [ j ] ] = v [ j ] ; mpp . Add ( v [ i ] + v [ j ] , 1 ) ; } } } s = v1 . Count ; for ( int i = 0 ; i < s ; i ++ ) { int el = n - ( v1 [ i ] ) ; if ( mpp . ContainsKey ( el ) ) { int a = mp1_first [ v1 [ i ] ] ; int b = mp1_second [ v1 [ i ] ] ; int c = mp1_first [ n - v1 [ i ] ] ; int d = mp1_second [ n - v1 [ i ] ] ; maxi = Math . Max ( a * b * c * d , maxi ) ; } } if ( maxi == - 1 ) Console . WriteLine ( " Not ▁ Possible " ) ; else { Console . WriteLine ( " The ▁ maximum ▁ product " + " ▁ is ▁ " + maxi ) ; } } public static void Main ( String [ ] args ) { int n = 50 ; findfactors ( n ) ; } }
Maximize the product of four factors of a Number | C # implementation of above approach ; Declare the ArrayList of factors for storing the ; function to find out the factors of a number ; Loop until the i reaches the sqrt ( n ) ; Check if i is a factor of n ; if both the factors are same we only push one factor ; factor1 is pushed ; factor2 is pushed ; Function to find the maximum product ; Initialize the product with - 1 ; Find the sum of factors and store it in s ; Compare whether it is equal to the n ; product of factors ; Check whether we have a better p now if yes update ; Driver Code ; initializes the List with the divisors of n ; prints out the maximised product .
using System ; using System . Collections . Generic ; class GFG { static List < int > factors = new List < int > ( 10 ) ; static void findFactors ( int n ) { for ( int i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( ( n / i ) == i ) { factors . Insert ( factors . Count , i ) ; } else { factors . Insert ( factors . Count , n / i ) ; factors . Insert ( factors . Count , i ) ; } } } } static int findProduct ( int n ) { int product = - 1 ; int si = factors . Count ; for ( int i = 0 ; i < si ; i ++ ) { for ( int j = 0 ; j < si ; j ++ ) { for ( int k = 0 ; k < si ; k ++ ) { for ( int l = 0 ; l < si ; l ++ ) { int s = factors [ i ] + factors [ j ] + factors [ k ] + factors [ l ] ; if ( s == n ) { int p = factors [ i ] * factors [ j ] * factors [ k ] * factors [ l ] ; if ( p > product ) { product = p ; } } } } } } return product ; } public static void Main ( String [ ] args ) { int n = 10 ; findFactors ( n ) ; Console . WriteLine ( findProduct ( n ) ) ; } }
Maximize the product of four factors of a Number | C # implementation of above approach ; For calculation of a ^ b ; Function to check ; every odd and number less than 3. ; every number divisible by 4. ; every number divisible by 6. ; every number divisible by 10. ; for every even number which is not divisible by above values . ; Driver code
using System ; public class GFG { static int modExp ( int a , int b ) { int result = 1 ; while ( b > 0 ) { if ( b == 1 ) result = result * a ; a = a * a ; b /= 2 ; } return result ; } static int check ( int num ) { if ( num == 1 num < 3 ) return - 1 ; else if ( num % 4 == 0 ) return modExp ( num / 4 , 4 ) ; else if ( num % 6 == 0 ) return modExp ( num / 3 , 2 ) * modExp ( num / 6 , 2 ) ; else if ( num % 10 == 0 ) return modExp ( num / 5 , 2 ) * ( num / 10 ) * ( num / 2 ) ; else return - 1 ; } static public void Main ( ) { int num = 10 ; Console . WriteLine ( check ( num ) ) ; } }
Check if any large number is divisible by 17 or not | C # Program to validate the above logic ; Function to check if the number is divisible by 17 or not ; Extracting the last digit ; Truncating the number ; Subtracting the five times the last digit from the remaining number ; Return n is divisible by 17 ; Driver code
using System ; class GFG { static bool isDivisible ( long n ) { while ( n / 100 > 0 ) { long d = n % 10 ; n /= 10 ; n -= d * 5 ; } return ( n % 17 == 0 ) ; } public static void Main ( ) { long n = 19877658 ; if ( isDivisible ( n ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Minimum number of elements to be removed to make XOR maximum | C # implementation to find minimum number of elements to remove to get maximum XOR value ; First n in the below condition is for the case where n is 0 ; Function to find minimum number of elements to be removed . ; Driver code ; print minimum number of elements to be removed
using System ; public class GFG { static int nextPowerOf2 ( int n ) { int count = 0 ; if ( n != 0 && ( n & ( n - 1 ) ) == 0 ) return n ; while ( n != 0 ) { n >>= 1 ; count += 1 ; } return 1 << count ; } static int removeElement ( int n ) { if ( n == 1 n == 2 ) return 0 ; int a = nextPowerOf2 ( n ) ; if ( n == a n == a - 1 ) return 1 ; else if ( n == a - 2 ) return 0 ; else if ( n % 2 == 0 ) return 1 ; else return 2 ; } public static void Main ( ) { int n = 5 ; Console . Write ( removeElement ( n ) ) ; } }
Program to find Length of Bridge using Speed and Length of Train | C # Program to implement above code ; function to calculate the length of bridge ; Driver Code ; Assuming the input variables
using System ; class GFG { static int bridge_length ( int trainLength , int Speed , int Time ) { return ( ( Time * Speed ) - trainLength ) ; } static void Main ( ) { int trainLength = 120 ; int Speed = 30 ; int Time = 18 ; Console . Write ( " Length ▁ of ▁ bridge ▁ = ▁ " + bridge_length ( trainLength , Speed , Time ) + " ▁ meters " ) ; } }