codeparrot/xlcost-text-to-code huggingface dataset:
Count numbers in a range having GCD of powers of prime factors equal to 1 | C # implementation of above idea ; List to store powers greater than 3 ; Set to store perfect squares ; Set to store powers other than perfect squares ; Pushing squares ; if the values is already a perfect square means present in the set ; Run loop until some power of current number doesn 't exceed MAX ; Pushing only odd powers as even power of a number can always be expressed as a perfect square which is already present in set squares ; Inserting those sorted values of set into a vector ; Precompute the powers ; Calculate perfect squares in range using sqrtl function ; Calculate upper value of R in vector using binary search ; Calculate lower value of L in vector using binary search ; Calculate perfect powers ; Compute readonly answer ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { static int N = 100005 ; static long MAX = ( long ) 1e18 ; static List < long > powers = new List < long > ( ) ; static HashSet < long > squares = new HashSet < long > ( ) ; static HashSet < long > s = new HashSet < long > ( ) ; static void powersPrecomputation ( ) { for ( long i = 2 ; i < N ; i ++ ) { squares . Add ( i * i ) ; if ( squares . Contains ( i ) ) continue ; long temp = i ; while ( i * i <= MAX / temp ) { temp *= ( i * i ) ; s . Add ( temp ) ; } } foreach ( long x in s ) powers . Add ( x ) ; } static long calculateAnswer ( long L , long R ) { powersPrecomputation ( ) ; long perfectSquares = ( long ) ( Math . Floor ( Math . Sqrt ( R ) ) - Math . Floor ( Math . Sqrt ( L - 1 ) ) ) ; long high = Array . BinarySearch ( powers . ToArray ( ) , R ) ; long low = Array . BinarySearch ( powers . ToArray ( ) , L ) ; long perfectPowers = perfectSquares + ( high - low ) ; long ans = ( R - L + 1 ) - perfectPowers ; return ans ; } public static void Main ( String [ ] args ) { long L = 13 , R = 20 ; Console . WriteLine ( calculateAnswer ( L , R ) ) ; } }
Split a number into 3 parts such that none of the parts is divisible by 3 | C # program to split a number into three parts such than none of them is divisible by 3. ; Print x = 1 , y = 1 and z = N - 2 ; Otherwise , print x = 1 , y = 2 and z = N - 3 ; Driver code
using System ; public class GFG { static void printThreeParts ( int N ) { if ( N % 3 == 0 ) Console . WriteLine ( " ▁ x ▁ = ▁ 1 , ▁ y ▁ = ▁ 1 , ▁ z ▁ = ▁ " + ( N - 2 ) ) ; else Console . WriteLine ( " ▁ x ▁ = ▁ 1 , ▁ y ▁ = ▁ 2 , ▁ z ▁ = ▁ " + ( N - 3 ) ) ; } static public void Main ( ) { int N = 10 ; printThreeParts ( N ) ; } }
Minimum absolute difference of a number and its closest prime | C # program to find the minimum absolute difference between a number and its closest prime ; Function to check if a number is prime or not ; Function to find the minimum absolute difference between a number and its closest prime ; Variables to store first prime above and below N ; Finding first prime number greater than N ; Finding first prime number less than N ; Variables to store the differences ; Driver code
using System ; class GFG { static bool isPrime ( int N ) { for ( int i = 2 ; i <= Math . Sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) return false ; } return true ; } static int getDifference ( int N ) { if ( N == 0 ) return 2 ; else if ( N == 1 ) return 1 ; else if ( isPrime ( N ) ) return 0 ; int aboveN = - 1 , belowN = - 1 ; int n1 ; n1 = N + 1 ; while ( true ) { if ( isPrime ( n1 ) ) { aboveN = n1 ; break ; } else n1 ++ ; } n1 = N - 1 ; while ( true ) { if ( isPrime ( n1 ) ) { belowN = n1 ; break ; } else n1 -- ; } int diff1 = aboveN - N ; int diff2 = N - belowN ; return Math . Min ( diff1 , diff2 ) ; } public static void Main ( ) { int N = 25 ; Console . WriteLine ( getDifference ( N ) ) ; } }
Check if the sum of perfect squares in an array is divisible by x | C # implementation of the approach ; Function that returns true if the the sum of all the perfect squares of the given array is divisible by x ; If arr [ i ] is a perfect square ; Driver Code
using System ; public class GFG { static bool check ( int [ ] arr , int x , int n ) { long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { double y = Math . Sqrt ( arr [ i ] ) ; if ( Math . Floor ( y ) == Math . Ceiling ( y ) ) { sum += arr [ i ] ; } } if ( sum % x == 0 ) return true ; else return false ; } public static void Main ( ) { int [ ] arr = { 2 , 3 , 4 , 9 , 10 } ; int n = arr . Length ; int x = 13 ; if ( check ( arr , x , n ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }
Largest Divisor of a Number not divisible by a perfect square | C # program to find the largest divisor not divisible by any perfect square greater than 1 ; Function to find the largest divisor not divisible by any perfect square greater than 1 ; Set to store divisors in descending order ; If the number is divisible by i , then insert it ; Vector to store perfect squares ; Check for each divisor , if it is not divisible by any perfect square , simply return it as the answer . ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int MAX = ( int ) 1e5 ; static int findLargestDivisor ( int n ) { int m = n ; HashSet < int > s = new HashSet < int > ( ) ; s . Add ( 1 ) ; s . Add ( n ) ; for ( int i = 2 ; i < ( int ) Math . Sqrt ( n ) + 1 ; i ++ ) { if ( n % i == 0 ) { s . Add ( n / i ) ; s . Add ( i ) ; while ( m % i == 0 ) m /= i ; } } if ( m > 1 ) s . Add ( m ) ; List < int > l = new List < int > ( s ) ; l . Sort ( ) ; l . Reverse ( ) ; List < int > vec = new List < int > ( ) ; for ( int i = 2 ; i <= MAX ; i ++ ) vec . Add ( i * i ) ; foreach ( int d in l ) { int divi = 0 ; for ( int j = 0 ; j < vec . Count && vec [ j ] <= d ; j ++ ) { if ( d % vec [ j ] == 0 ) { divi = 1 ; break ; } } if ( divi == 0 ) return d ; } return 0 ; } static void Main ( ) { int n = 12 ; Console . WriteLine ( findLargestDivisor ( n ) ) ; n = 97 ; Console . WriteLine ( findLargestDivisor ( n ) ) ; } }
Minimum and Maximum number of pairs in m teams of n people | C # program to find minimum and maximum no . of pairs ; Driver code
using System ; class GFG { static void MinimumMaximumPairs ( int n , int m ) { int max_pairs = ( ( n - m + 1 ) * ( n - m ) ) / 2 ; int min_pairs = m * ( ( ( n - m ) / m + 1 ) * ( ( n - m ) / m ) ) / 2 + ( int ) Math . Ceiling ( ( double ) ( ( n - m ) / ( double ) ( m ) ) ) * ( ( n - m ) % m ) ; Console . WriteLine ( " Minimum ▁ no . ▁ of ▁ pairs ▁ = ▁ " + min_pairs ) ; Console . WriteLine ( " Maximum ▁ no . ▁ of ▁ pairs ▁ = ▁ " + max_pairs ) ; } public static void Main ( ) { int n = 5 , m = 2 ; MinimumMaximumPairs ( n , m ) ; } }
Larger of a ^ b or b ^ a ( a raised to power b or b raised to power a ) | C # code for finding greater between the a ^ b and b ^ a ; Function to find the greater value ; Driver code
using System ; public class GFG { static void findGreater ( int a , int b ) { double x = ( double ) a * ( double ) ( Math . Log ( ( double ) ( b ) ) ) ; double y = ( double ) b * ( double ) ( Math . Log ( ( double ) ( a ) ) ) ; if ( y > x ) { Console . Write ( " a ^ b ▁ is ▁ greater STRNEWLINE " ) ; } else if ( y < x ) { Console . Write ( " b ^ a ▁ is ▁ greater " + " STRNEWLINE " ) ; } else { Console . Write ( " Both ▁ are ▁ equal " ) ; } } public static void Main ( ) { int a = 3 , b = 5 , c = 2 , d = 4 ; findGreater ( a , b ) ; findGreater ( c , d ) ; } }
Expressing a fraction as a natural number under modulo ' m ' | C # implementation of the approach ; Function to return the GCD of given numbers ; Recursive function to return ( x ^ n ) % m ; Function to return the fraction modulo mod ; ( b ^ m - 2 ) % m ; Final answer ; Driver code
using System ; public class GFG { static long m = 1000000007 ; static long gcd ( long a , long b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static long modexp ( long x , long n ) { if ( n == 0 ) { return 1 ; } else if ( n % 2 == 0 ) { return modexp ( ( x * x ) % m , n / 2 ) ; } else { return ( x * modexp ( ( x * x ) % m , ( n - 1 ) / 2 ) % m ) ; } } static long getFractionModulo ( long a , long b ) { long c = gcd ( a , b ) ; a = a / c ; b = b / c ; long d = modexp ( b , m - 2 ) ; long ans = ( ( a % m ) * ( d % m ) ) % m ; return ans ; } static public void Main ( ) { long a = 2 , b = 6 ; Console . WriteLine ( getFractionModulo ( a , b ) ) ; } }
Find sum of a number and its maximum prime factor | C # program to find sum of n and it 's largest prime factor ; Function to return the sum of n and it 's largest prime factor ; Initialise maxPrime to - 1. ; n must be odd at this point , thus skip the even numbers and iterate only odd numbers ; This condition is to handle the case when n is a prime number greater than 2 ; finally return the sum . ; Driver Code
using System ; class GFG { static int maxPrimeFactors ( int n ) { int num = n ; int maxPrime = - 1 ; while ( n % 2 == 0 ) { maxPrime = 2 ; n /= 2 ; } for ( int i = 3 ; i <= Math . Sqrt ( n ) ; i += 2 ) { while ( n % i == 0 ) { maxPrime = i ; n = n / i ; } } if ( n > 2 ) { maxPrime = n ; } int sum = maxPrime + num ; return sum ; } static void Main ( ) { int n = 19 ; Console . WriteLine ( maxPrimeFactors ( n ) ) ; } }
Largest number less than N with digit sum greater than the digit sum of N | C # implementation of the approach ; Function to return the sum of the digits of n ; Loop for each digit of the number ; Function to return the greatest number less than n such that the sum of its digits is greater than the sum of the digits of n ; Starting from n - 1 ; Check until 1 ; If i satisfies the given condition ; If the condition is not satisfied ; Driver code
using System ; class GFG { static int sumOfDigits ( int n ) { int res = 0 ; while ( n > 0 ) { res += n % 10 ; n /= 10 ; } return res ; } static int findNumber ( int n ) { int i = n - 1 ; while ( i > 0 ) { if ( sumOfDigits ( i ) > sumOfDigits ( n ) ) return i ; i -- ; } return - 1 ; } static public void Main ( ) { int n = 824 ; Console . WriteLine ( findNumber ( n ) ) ; } }
Find the Nth term of the series 14 , 28 , 20 , 40 , ... . . | C # program to find the Nth term of the series 14 , 28 , 20 , 40 , ; Function to find the N - th term ; initializing the 1 st number ; loop from 2 nd term to nth term ; if i is even , double the previous number ; if i is odd , subtract 8 from previous number ; Driver Code
using System ; public class GFG { static int findNth ( int N ) { int b = 14 ; int i ; for ( i = 2 ; i <= N ; i ++ ) { if ( i % 2 == 0 ) b = b * 2 ; else b = b - 8 ; } return b ; } static public void Main ( ) { int N = 6 ; Console . WriteLine ( findNth ( N ) ) ; } }
Problem of 8 Neighbours of an element in a 2 | C # implementation of the approach ; Dimension of Array ; Count of 1 s ; Counting all neighbouring 1 s ; Comparing the number of neighbouring 1 s with given ranges ; Copying changes to the main matrix ; Driver code ; Function call to calculate the resultant matrix after ' K ' iterations . ; Printing Result
using System ; class GFG { readonly static int N = 4 ; static void predictMatrix ( int [ , ] arr , int range1a , int range1b , int range0a , int range0b , int K , int [ , ] b ) { int c = 0 ; while ( K != 0 ) { K -- ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { c = 0 ; if ( i > 0 && arr [ i - 1 , j ] == 1 ) c ++ ; if ( j > 0 && arr [ i , j - 1 ] == 1 ) c ++ ; if ( i > 0 && j > 0 && arr [ i - 1 , j - 1 ] == 1 ) c ++ ; if ( i < N - 1 && arr [ i + 1 , j ] == 1 ) c ++ ; if ( j < N - 1 && arr [ i , j + 1 ] == 1 ) c ++ ; if ( i < N - 1 && j < N - 1 && arr [ i + 1 , j + 1 ] == 1 ) c ++ ; if ( i < N - 1 && j > 0 && arr [ i + 1 , j - 1 ] == 1 ) c ++ ; if ( i > 0 && j < N - 1 && arr [ i - 1 , j + 1 ] == 1 ) c ++ ; if ( arr [ i , j ] == 1 ) { if ( c >= range1a && c <= range1b ) b [ i , j ] = 1 ; else b [ i , j ] = 0 ; } if ( arr [ i , j ] == 0 ) { if ( c >= range0a && c <= range0b ) b [ i , j ] = 1 ; else b [ i , j ] = 0 ; } } } for ( int k = 0 ; k < N ; k ++ ) for ( int m = 0 ; m < N ; m ++ ) arr [ k , m ] = b [ k , m ] ; } } public static void Main ( ) { int [ , ] arr = { { 0 , 0 , 0 , 0 } , { 0 , 1 , 1 , 0 } , { 0 , 0 , 1 , 0 } , { 0 , 1 , 0 , 1 } } ; int range1a = 2 , range1b = 2 ; int range0a = 2 , range0b = 3 ; int K = 3 ; int [ , ] b = new int [ N , N ] ; predictMatrix ( arr , range1a , range1b , range0a , range0b , K , b ) ; for ( int i = 0 ; i < N ; i ++ ) { Console . WriteLine ( ) ; for ( int j = 0 ; j < N ; j ++ ) Console . Write ( b [ i , j ] + " ▁ " ) ; } } }
Number of moves required to guess a permutation . | C # implementation of the approach ; Function that returns the required moves ; Final move ; Driver Program to test above function
using System ; class GFG { static int countMoves ( int n ) { int ct = 0 ; for ( int i = 1 ; i <= n ; i ++ ) ct += i * ( n - i ) ; ct += n ; return ct ; } static void Main ( ) { int n = 3 ; Console . WriteLine ( countMoves ( n ) ) ; } }
Count number of triplets ( a , b , c ) such that a ^ 2 + b ^ 2 = c ^ 2 and 1 <= a <= b <= c <= n | C # implementation of the approach ; Function to return an ArrayList containing all the perfect squares upto n ; while current perfect square is less than or equal to n ; Function to return the count of triplet ( a , b , c ) pairs such that a ^ 2 + b ^ 2 = c ^ 2 and 1 <= a <= b <= c <= n ; List of perfect squares upto n ^ 2 ; Since , a ^ 2 + b ^ 2 = c ^ 2 ; If c < a or bSquare is not a perfect square ; If triplet pair ( a , b , c ) satisfy the given condition ; Driver code
using System . Collections ; using System ; class GFG { public static ArrayList getPerfectSquares ( int n ) { ArrayList perfectSquares = new ArrayList ( ) ; int current = 1 , i = 1 ; while ( current <= n ) { perfectSquares . Add ( current ) ; current = ( int ) Math . Pow ( ++ i , 2 ) ; } return perfectSquares ; } public static int countTriplets ( int n ) { ArrayList perfectSquares = getPerfectSquares ( ( int ) Math . Pow ( n , 2 ) ) ; int count = 0 ; for ( int a = 1 ; a <= n ; a ++ ) { int aSquare = ( int ) Math . Pow ( a , 2 ) ; for ( int i = 0 ; i < perfectSquares . Count ; i ++ ) { int cSquare = ( int ) perfectSquares [ i ] ; int bSquare = cSquare - aSquare ; int b = ( int ) Math . Sqrt ( bSquare ) ; int c = ( int ) Math . Sqrt ( cSquare ) ; if ( c < a || ! perfectSquares . Contains ( bSquare ) ) continue ; if ( ( b >= a ) && ( b <= c ) && ( aSquare + bSquare == cSquare ) ) count ++ ; } } return count ; } public static void Main ( ) { int n = 10 ; Console . WriteLine ( countTriplets ( n ) ) ; } }
Count Numbers with N digits which consists of even number of 0 ’ s | C # program to count numbers with N digits which consists of odd number of 0 's ; Function to count Numbers with N digits which consists of odd number of 0 's ; Driver code
using System ; class GFG { static double countNumbers ( int N ) { return ( Math . Pow ( 10 , N ) - 1 ) - ( Math . Pow ( 10 , N ) - Math . Pow ( 8 , N ) ) / 2 ; } static public void Main ( ) { int n = 2 ; Console . WriteLine ( countNumbers ( n ) ) ; } }
Find determinant of matrix generated by array rotation | C # program for finding determinant of generated matrix ; Function to calculate determinant ; Driver code
using System ; class GFG { static int N = 3 ; static double calcDeterminant ( int [ ] arr ) { double determinant = 0 ; for ( int i = 0 ; i < N ; i ++ ) { determinant += Math . Pow ( arr [ i ] , 3 ) ; } determinant -= 3 * arr [ 0 ] * arr [ 1 ] * arr [ 2 ] ; return determinant ; } static public void Main ( ) { int [ ] arr = { 4 , 5 , 3 } ; Console . WriteLine ( calcDeterminant ( arr ) ) ; } }
Minimum elements to be added in a range so that count of elements is divisible by K | C # implementation of the approach ; Total elements in the range ; If total elements are already divisible by k ; Value that must be added to count in order to make it divisible by k ; Driver Program to test above function
using System ; class GFG { static int minimumMoves ( int k , int l , int r ) { int count = r - l + 1 ; if ( count % k == 0 ) return 0 ; return ( k - ( count % k ) ) ; } public static void Main ( ) { int k = 3 , l = 10 , r = 10 ; Console . WriteLine ( minimumMoves ( k , l , r ) ) ; } }
Sum of all even numbers in range L and R | C # program to print the sum of all even numbers in range L and R ; Function to return the sum of all natural numbers ; Function to return sum of even numbers in range L and R ; Driver Code
using System ; public class GFG { static int sumNatural ( int n ) { int sum = ( n * ( n + 1 ) ) ; return sum ; } static int sumEven ( int l , int r ) { return sumNatural ( r / 2 ) - sumNatural ( ( l - 1 ) / 2 ) ; } static public void Main ( ) { int l = 2 , r = 5 ; Console . WriteLine ( " Sum ▁ of ▁ Natural ▁ numbers ▁ from ▁ L ▁ to ▁ R ▁ is ▁ " + sumEven ( l , r ) ) ; } }
Check if N is divisible by a number which is composed of the digits from the set { A , B } | C # program to find if number N is divisible by a number that contains only a and b as it 's digits ; Function to check whether n is divisible by a number whose digits are either a or b ; base condition ; recursive call ; Check for all numbers beginning with ' a ' or ' b ' ; Driver Code
using System ; class GFG { static bool isDivisibleRec ( int x , int a , int b , int n ) { if ( x > n ) return false ; if ( n % x == 0 ) return true ; return ( isDivisibleRec ( x * 10 + a , a , b , n ) || isDivisibleRec ( x * 10 + b , a , b , n ) ) ; } static bool isDivisible ( int a , int b , int n ) { return isDivisibleRec ( a , a , b , n ) || isDivisibleRec ( b , a , b , n ) ; } static public void Main ( ) { int a = 3 , b = 5 , n = 53 ; if ( isDivisible ( a , b , n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Minimum number of moves required to reach the destination by the king in a chess board | C # program to Find the minimum number of moves required to reach the destination by the king in a chess board ; function to Find the minimum number of moves required to reach the destination by the king in a chess board ; minimum number of steps ; while the king is not in the same row or column as the destination ; Go up ; Go down ; Go left ; Go right ; Driver code
using System ; class GFG { static void MinSteps ( int SourceX , int SourceY , int DestX , int DestY ) { Console . WriteLine ( Math . Max ( Math . Abs ( SourceX - DestX ) , Math . Abs ( SourceY - DestY ) ) ) ; while ( ( SourceX != DestX ) || ( SourceY != DestY ) ) { if ( SourceX < DestX ) { Console . Write ( ' U ' ) ; SourceX ++ ; } if ( SourceX > DestX ) { Console . Write ( ' D ' ) ; SourceX -- ; } if ( SourceY > DestY ) { Console . Write ( ' L ' ) ; SourceY -- ; } if ( SourceY < DestY ) { Console . Write ( ' R ' ) ; SourceY ++ ; } Console . WriteLine ( ) ; } } public static void Main ( ) { int sourceX = 4 , sourceY = 4 ; int destinationX = 7 , destinationY = 0 ; MinSteps ( sourceX , sourceY , destinationX , destinationY ) ; } }
Count of pairs in an array whose sum is a perfect square | C # implementation of the approach ; Function to return an ArrayList containing all the perfect squares upto n ; while current perfect square is less than or equal to n ; Function to print the sum of maximum two elements from the array ; Function to return the count of numbers that when added with n give a perfect square ; temp > n is checked so that pairs ( x , y ) and ( y , x ) don 't get counted twice  ; Function to count the pairs whose sum is a perfect square ; Sum of the maximum two elements from the array ; List of perfect squares upto max ; Contains all the array elements ; Add count of the elements that when added with arr [ i ] give a perfect square ; Driver code
using System ; using System . Collections ; using System . Collections . Generic ; public class GFG { public static ArrayList getPerfectSquares ( int n ) { ArrayList perfectSquares = new ArrayList ( ) ; int current = 1 , i = 1 ; while ( current <= n ) { perfectSquares . Add ( current ) ; current = ( int ) Math . Pow ( ++ i , 2 ) ; } return perfectSquares ; } public static int maxPairSum ( int [ ] arr ) { int n = arr . Length ; int max , secondMax ; if ( arr [ 0 ] > arr [ 1 ] ) { max = arr [ 0 ] ; secondMax = arr [ 1 ] ; } else { max = arr [ 1 ] ; secondMax = arr [ 0 ] ; } for ( int i = 2 ; i < n ; i ++ ) { if ( arr [ i ] > max ) { secondMax = max ; max = arr [ i ] ; } else if ( arr [ i ] > secondMax ) { secondMax = arr [ i ] ; } } return ( max + secondMax ) ; } public static int countPairsWith ( int n , ArrayList perfectSquares , ArrayList nums ) { int count = 0 ; for ( int i = 0 ; i < perfectSquares . Count ; i ++ ) { int temp = ( int ) perfectSquares [ i ] - n ; if ( temp > n && nums . Contains ( temp ) ) count ++ ; } return count ; } public static int countPairs ( int [ ] arr ) { int i , n = arr . Length ; int max = maxPairSum ( arr ) ; ArrayList perfectSquares = getPerfectSquares ( max ) ; ArrayList nums = new ArrayList ( ) ; for ( i = 0 ; i < n ; i ++ ) nums . Add ( arr [ i ] ) ; int count = 0 ; for ( i = 0 ; i < n ; i ++ ) { count += countPairsWith ( arr [ i ] , perfectSquares , nums ) ; } return count ; } public static void Main ( ) { int [ ] arr = { 2 , 3 , 6 , 9 , 10 , 20 } ; Console . WriteLine ( countPairs ( arr ) ) ; } }
Element equal to the sum of all the remaining elements | C # implementation of the above approach ; Function to find the element ; sum is use to store sum of all elements of array ; iterate over all elements ; Driver code
using System ; class GFG { static int findEle ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] == sum - arr [ i ] ) return arr [ i ] ; return - 1 ; } static public void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 6 } ; int n = arr . Length ; Console . WriteLine ( findEle ( arr , n ) ) ; } }
Sum of all natural numbers in range L to R | C # program to print the sum of all numbers in range L and R ; Function to return the sum of all natural numbers ; Function to return the sum of all numbers in range L and R ; Driver Code
using System ; class GFG { static int sumNatural ( int n ) { int sum = ( n * ( n + 1 ) ) / 2 ; return sum ; } static int suminRange ( int l , int r ) { return sumNatural ( r ) - sumNatural ( l - 1 ) ; } static public void Main ( ) { int l = 2 , r = 5 ; Console . WriteLine ( " Sum ▁ of ▁ Natural ▁ numbers ▁ " + " from ▁ L ▁ to ▁ R ▁ is ▁ " + suminRange ( l , r ) ) ; } }
Check if a large number is divisible by 75 or not | C # implementation to check the number is divisible by 75 or not ; check divisibleBy3 ; to store sum of Digit ; traversing through each digit ; summing up Digit ; check if sumOfDigit is divisibleBy3 ; check divisibleBy25 ; if a single digit number ; length of the number ; taking the last two digit ; checking if the lastTwo digit is divisibleBy25 ; Function to check divisibleBy75 or not ; check if divisibleBy3 and divisibleBy25 ; Driver Code ; divisible ; if divisibleBy75
using System ; class GFG { static bool divisibleBy3 ( string number ) { int sumOfDigit = 0 ; for ( int i = 0 ; i < number . Length ; i ++ ) sumOfDigit += number [ i ] - '0' ; if ( sumOfDigit % 3 == 0 ) return true ; return false ; } static bool divisibleBy25 ( string number ) { if ( number . Length < 2 ) return false ; int length = number . Length ; int lastTwo = ( number [ length - 2 ] - '0' ) * 10 + ( number [ length - 1 ] - '0' ) ; if ( lastTwo % 25 == 0 ) return true ; return false ; } static bool divisibleBy75 ( string number ) { if ( divisibleBy3 ( number ) && divisibleBy25 ( number ) ) return true ; return false ; } public static void Main ( ) { string number = "754586672150" ; bool divisible = divisibleBy75 ( number ) ; if ( divisible ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Find the other number when LCM and HCF given | C # program to find other number from given HCF and LCM ; Function that will calculates the zeroes at the end ; Driver code ; Calling function .
using System ; class GFG { static int otherNumber ( int A , int Lcm , int Hcf ) { return ( Lcm * Hcf ) / A ; } static public void Main ( String [ ] args ) { int A = 8 , Lcm = 8 , Hcf = 1 ; int result = otherNumber ( A , Lcm , Hcf ) ; Console . WriteLine ( " B ▁ = ▁ " + result ) ; } }