codeparrot/xlcost-text-to-code huggingface dataset:
GCD of a number raised to some power and another number | C # program of the above approach ; Calculates modular exponentiation , i . e . , ( x ^ y ) % p in O ( log y ) ; x = x % p ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; Returns GCD of a ^ n and b ; Driver code
using System ; class GFG { static long power ( long x , long y , long p ) { while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } static long gcd ( long a , long b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static long powerGCD ( long a , long b , long n ) { long e = power ( a , n , b ) ; return gcd ( e , b ) ; } public static void Main ( ) { long a = 5 , b = 4 , n = 2 ; Console . Write ( powerGCD ( a , b , n ) ) ; } }
Largest number not greater than N all the digits of which are odd | C # program to print the largest integer not greater than N with all odd digits ; Function to check if all digits of a number are odd ; iterate for all digits ; if digit is even ; all digits are odd ; function to return the largest number with all digits odd ; iterate till we find a number with all digits odd ; Driver Code
using System ; class GFG { static bool allOddDigits ( int n ) { while ( n != 0 ) { if ( ( n % 10 ) % 2 == 0 ) return false ; n /= 10 ; } return true ; } static int largestNumber ( int n ) { if ( n % 2 == 0 ) n -- ; for ( int i = n ; ; i -= 2 ) if ( allOddDigits ( i ) ) return i ; } public static void Main ( ) { int N = 23 ; Console . WriteLine ( largestNumber ( N ) ) ; } }
Largest number not greater than N all the digits of which are odd | C # program to print the largest integer not greater than N with all odd digits ; function to return the largest number with all digits odd ; convert the number to a string for easy operations ; find first even digit ; if no even digit , then N is the answer ; till first even digit , add all odd numbers ; decrease 1 from the even digit ; add 9 in the rest of the digits ; Driver Code
using System ; class GFG { static int largestNumber ( int n ) { string s = " " ; int duplicate = n ; while ( n > 0 ) { s = ( char ) ( n % 10 + 48 ) + s ; n /= 10 ; } int index = - 1 ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( ( ( int ) ( s [ i ] - '0' ) % 2 & 1 ) == 0 ) { index = i ; break ; } } if ( index == - 1 ) return duplicate ; int num = 0 ; for ( int i = 0 ; i < index ; i ++ ) num = num * 10 + ( int ) ( s [ i ] - '0' ) ; num = num * 10 + ( ( int ) s [ index ] - ( int ) ( '0' ) - 1 ) ; for ( int i = index + 1 ; i < s . Length ; i ++ ) num = num * 10 + 9 ; return num ; } static void Main ( ) { int N = 24578 ; Console . WriteLine ( largestNumber ( N ) ) ; } }
Count number less than N which are product of perfect squares | C # program to count number less than N which are product of any two perfect squares ; Function to count number less than N which are product of any two perfect squares ; Driver Code
using System ; class GFG { static int countNumbers ( int N ) { return ( int ) ( Math . Sqrt ( N ) ) - 1 ; } public static void Main ( ) { int N = 36 ; Console . Write ( countNumbers ( N ) ) ; } }
Count ordered pairs with product less than N | C # implementation of above approach ; Function to return count of Ordered pairs whose product are less than N ; Initialize count to 0 ; count total pairs ; multiply by 2 to get ordered_pairs ; subtract redundant pairs ( a , b ) where a == b . ; return answer ; Driver code ; function call to print required answer
using System ; public class GFG { static int countOrderedPairs ( int N ) { int count_pairs = 0 ; for ( int i = 1 ; i <= ( int ) Math . Sqrt ( N - 1 ) ; ++ i ) { for ( int j = i ; j * i < N ; ++ j ) ++ count_pairs ; } count_pairs *= 2 ; count_pairs -= ( int ) ( Math . Sqrt ( N - 1 ) ) ; return count_pairs ; } static public void Main ( ) { int N = 5 ; Console . WriteLine ( countOrderedPairs ( N ) ) ; } }
Absolute Difference of all pairwise consecutive elements in an array | C # program to print the absolute difference of the consecutive elements ; Function to print pairwise absolute difference of consecutive elements ; absolute difference between consecutive numbers ; Driver Code
using System ; class GFG { static void pairwiseDifference ( int [ ] arr , int n ) { int diff ; for ( int i = 0 ; i < n - 1 ; i ++ ) { diff = Math . Abs ( arr [ i ] - arr [ i + 1 ] ) ; Console . WriteLine ( diff + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 10 , 15 , 5 , 6 } ; int n = arr . Length ; pairwiseDifference ( arr , n ) ; } }
Find the sum of all multiples of 2 and 5 below N | C # program to find the sum of all multiples of 2 and 5 below N ; Function to find sum of AP series ; Number of terms ; Function to find the sum of all multiples of 2 and 5 below N ; Since , we need the sum of multiples less than N ; Driver code
using System ; public class GFG { static long sumAP ( long n , long d ) { n /= d ; return ( n ) * ( 1 + n ) * d / 2 ; } static long sumMultiples ( long n ) { n -- ; return sumAP ( n , 2 ) + sumAP ( n , 5 ) - sumAP ( n , 10 ) ; } static public void Main ( ) { long n = 20 ; Console . WriteLine ( sumMultiples ( n ) ) ; } }
Find the total marks obtained according to given marking scheme | C # implementation of above approach ; Function that calculates marks . ; for not attempt score + 0 ; for each correct answer score + 3 ; for each wrong answer score - 1 ; calculate total marks ; Driver code
using System ; class GFG { static int markingScheme ( int N , int [ ] answerKey , int [ ] studentAnswer ) { int positive = 0 , negative = 0 , notattempt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( studentAnswer [ i ] == 0 ) notattempt ++ ; else if ( answerKey [ i ] == studentAnswer [ i ] ) positive ++ ; else if ( answerKey [ i ] != studentAnswer [ i ] ) negative ++ ; } return ( positive * 3 ) + ( negative * - 1 ) ; } static public void Main ( ) { int [ ] answerKey = { 1 , 2 , 3 , 4 , 1 } ; int [ ] studentAnswer = { 1 , 2 , 3 , 4 , 0 } ; int N = answerKey . Length ; int marking_Scheme = markingScheme ( N , answerKey , studentAnswer ) ; Console . WriteLine ( marking_Scheme ) ; } }
Find the Product of first N Prime Numbers | C # implementation of above solution ; Create a boolean array " prime [ 0 . . n ] " and initialize all entries it as true . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Set all multiples of p to non - prime ; find the product of 1 st N prime numbers ; count of prime numbers ; product of prime numbers ; if the number is prime add it ; increase the count ; get to next number ; Driver code ; create the sieve ; find the value of 1 st n prime numbers
class GFG { static int MAX = 10000 ; static bool [ ] prime = new bool [ MAX + 1 ] ; static void SieveOfEratosthenes ( ) { prime [ 1 ] = true ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == false ) { for ( int i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = true ; } } } static int solve ( int n ) { int count = 0 , num = 1 ; int prod = 1 ; while ( count < n ) { if ( ! prime [ num ] ) { prod *= num ; count ++ ; } num ++ ; } return prod ; } public static void Main ( ) { SieveOfEratosthenes ( ) ; int n = 5 ; System . Console . WriteLine ( solve ( n ) ) ; } }
Program to find count of numbers having odd number of divisors in given range | C # implementation of the approach ; Function to return the count of divisors of a number ; Count the powers of the current prime i which divides a ; Update the count of divisors ; Reset the count ; If the remaining a is prime then a ^ 1 will be one of its prime factors ; Function to count numbers having odd number of divisors in range [ A , B ] ; To store the count of elements having odd number of divisors ; Iterate from a to b and find the count of their divisors ; To store the count of divisors of i ; If the divisor count of i is odd ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int divisor ( int a ) { int div = 1 , count = 0 ; for ( int i = 2 ; i <= Math . Sqrt ( a ) ; i ++ ) { while ( a % i == 0 ) { count ++ ; a = a / i ; } div = div * ( count + 1 ) ; count = 0 ; } if ( a > 1 ) { div = div * ( 2 ) ; } return div ; } static int OddDivCount ( int a , int b ) { int res = 0 ; for ( int i = a ; i <= b ; ++ i ) { int divCount = divisor ( i ) ; if ( divCount % 2 == 1 ) { ++ res ; } } return res ; } public static void Main ( String [ ] args ) { int a = 1 , b = 10 ; Console . WriteLine ( OddDivCount ( a , b ) ) ; } }
Check if there is any pair in a given range with GCD is divisible by k | C # program to count the numbers divisible by k in a given range ; Returns count of numbers in [ l r ] that are divisible by k . ; Add 1 explicitly as l is divisible by k ; l is not divisible by k ; Driver Code
using System ; public class GFG { static bool Check_is_possible ( int l , int r , int k ) { int div_count = ( r / k ) - ( l / k ) ; if ( l % k == 0 ) { div_count ++ ; } return ( div_count > 1 ) ; } public static void Main ( ) { int l = 30 , r = 70 , k = 10 ; if ( Check_is_possible ( l , r , k ) ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } }
Find sum of N | C # program to find sum in Nth group ; calculate sum of Nth group ; Driver code
using System ; class gfg { public static double nth_group ( int n ) { return n * ( 2 * Math . Pow ( n , 2 ) + 1 ) ; } public static int Main ( ) { int N = 5 ; Console . WriteLine ( nth_group ( N ) ) ; return 0 ; } }
Find if a molecule can be formed from 3 atoms using their valence numbers | C # implementation of the above approach ; Function to check if it is possible ; Driver code
using System ; class GFG { static void printPossible ( int a , int b , int c ) { if ( ( a + b + c ) % 2 != 0 a + b < c ) Console . Write ( " NO " ) ; else Console . Write ( " YES " ) ; } public static void Main ( ) { int a = 2 , b = 4 , c = 2 ; printPossible ( a , b , c ) ; } }
Check if a number is a Trojan Number | C # program to check if a number is Trojan Number or not ; Function to check if a number can be expressed as x ^ y ; Try all numbers from 2 to sqrt ( n ) as base ; Keep increasing y while power ' p ' is smaller than n . ; Function to check if a number is Strong ; count the number for each prime factor ; minimum number of prime divisors should be 2 ; Function to check if a number is Trojan Number ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static bool isPerfectPower ( int n ) { if ( n == 1 ) { return true ; } for ( int x = 2 ; x <= Math . Sqrt ( n ) ; x ++ ) { int y = 2 ; int p = ( int ) Math . Pow ( x , y ) ; while ( p <= n && p > 0 ) { if ( p == n ) { return true ; } y ++ ; p = ( int ) Math . Pow ( x , y ) ; } } return false ; } static bool isStrongNumber ( int n ) { Dictionary < int , int > count = new Dictionary < int , int > ( ) ; while ( n % 2 == 0 ) { n = n / 2 ; if ( count . ContainsKey ( 2 ) ) { count [ 2 ] = count [ 2 ] + 1 ; } else { count . Add ( 2 , 1 ) ; } } for ( int i = 3 ; i <= Math . Sqrt ( n ) ; i += 2 ) { while ( n % i == 0 ) { n = n / i ; if ( count . ContainsKey ( i ) ) { count [ i ] = count [ i ] + 1 ; } else { count . Add ( i , 1 ) ; } } } if ( n > 2 ) { if ( count . ContainsKey ( n ) ) { count [ n ] = count [ n ] + 1 ; } else { count . Add ( n , 1 ) ; } } int flag = 0 ; foreach ( KeyValuePair < int , int > b in count ) { if ( b . Value == 1 ) { flag = 1 ; break ; } } if ( flag == 1 ) { return false ; } else { return true ; } } static bool isTrojan ( int n ) { if ( ! isPerfectPower ( n ) && isStrongNumber ( n ) ) { return true ; } else { return false ; } } public static void Main ( String [ ] args ) { int n = 108 ; if ( isTrojan ( n ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Find the sum of first N terms of the series 2 Ã — 3 + 4 Ã — 4 + 6 Ã — 5 + 8 Ã — 6 + ... | C # program to find sum upto N term of the series : 2 A 3 + 4 A 4 + 6 A 5 + 8 A 6 + ... ; calculate sum upto N term of series ; Driver code
using System ; class GFG { static void Sum_upto_nth_Term ( int n ) { int r = n * ( n + 1 ) * ( 2 * n + 7 ) / 3 ; Console . Write ( r ) ; } public static void Main ( ) { int N = 5 ; Sum_upto_nth_Term ( N ) ; } }
Absolute Difference between the Sum of Non | C # program to find the Absolute Difference between the Sum of Non - Prime numbers and Prime numbers of an Array ; Function to find the difference between the sum of non - primes and the sum of primes of an array . ; Find maximum value in the array ; USE SIEVE TO FIND ALL PRIME NUMBERS LESS THAN OR EQUAL TO max_val Create a boolean array " prime [ 0 . . n ] " . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; Remaining part of SIEVE ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Store the sum of primes in S1 and the sum of non primes in S2 ; the number is prime ; the number is non - prime ; Return the absolute difference ; Driver Code ; Get the array ; Find the absolute difference
using System ; class GFG { static int CalculateDifference ( int [ ] arr , int n ) { int max_val = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > max_val ) max_val = arr [ i ] ; } bool [ ] prime = new bool [ max_val + 1 ] ; for ( int i = 0 ; i <= max_val ; i ++ ) prime [ i ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int S1 = 0 , S2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) { S1 += arr [ i ] ; } else if ( arr [ i ] != 1 ) { S2 += arr [ i ] ; } } return Math . Abs ( S2 - S1 ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 1 , 3 , 5 , 10 , 15 , 7 } ; int n = arr . Length ; Console . WriteLine ( CalculateDifference ( arr , n ) ) ; } }
Program to find sum of 1 + x / 2 ! + x ^ 2 / 3 ! + ... + x ^ n / ( n + 1 ) ! | C # implementation of the approach ; Function to compute the series sum ; To store the value of S [ i - 1 ] ; Iterate over n to store sum in total ; Update previous with S [ i ] ; Driver code ; Get x and n ; Find and print the sum
using System ; class GFG { public double sum ( int x , int n ) { double total = 1.0 ; double previous = 1.0 ; for ( int i = 1 ; i <= n ; i ++ ) { previous = ( ( previous * x ) / ( i + 1 ) ) ; total = total + previous ; } return total ; } } class geek { public static void Main ( ) { GFG g = new GFG ( ) ; int x = 5 , n = 4 ; Console . WriteLine ( " Sum ▁ is : ▁ " + g . sum ( x , n ) ) ; } }
Count number of integers less than or equal to N which has exactly 9 divisors | C # implementation of above approach ; Function to count factors in O ( N ) ; iterate and check if factor or not ; Function to count numbers having exactly 9 divisors ; check for all numbers <= N ; check if exactly 9 factors or not ; Driver Code
using System ; class GFG { static int numberOfDivisors ( int num ) { int c = 0 ; for ( int i = 1 ; i <= num ; i ++ ) { if ( num % i == 0 ) { c += 1 ; } } return c ; } static int countNumbers ( int n ) { int c = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( numberOfDivisors ( i ) == 9 ) c += 1 ; } return c ; } public static void Main ( ) { int n = 1000 ; Console . Write ( countNumbers ( n ) ) ; } }
Number of distinct integers obtained by lcm ( X , N ) / X | C # program to find distinct integers ontained by lcm ( x , num ) / x ; Function to count the number of distinct integers ontained by lcm ( x , num ) / x ; iterate to count the number of factors ; Driver Code
using System ; class GFG { static int numberOfDistinct ( int n ) { int ans = 0 ; for ( int i = 1 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { ans ++ ; if ( ( n / i ) != i ) ans ++ ; } } return ans ; } static public void Main ( ) { int n = 3 ; Console . WriteLine ( numberOfDistinct ( n ) ) ; } }
Ulam Number Sequence | C # code to print nth Ulam number ; Array to store Ulam Number ; Function to compute ulam Number ; push First 2 two term of the sequence in the array for further calculation ; loop to generate Ulam number ; traverse the array and check if i can be represented as sum of two distinct element of the array ; If count is 2 that means i can be represented as sum of two distinct terms of the sequence ; i is ulam number ; Driver code ; pre compute Ulam Number sequence ; print nth Ulam number
using System ; using System . Collections . Generic ; class GFG { static readonly int MAX = 1000 ; static List < int > arr = new List < int > ( ) ; static void ulam ( ) { arr . Add ( 1 ) ; arr . Add ( 2 ) ; for ( int i = 3 ; i < MAX ; i ++ ) { int count = 0 ; for ( int j = 0 ; j < arr . Count - 1 ; j ++ ) { for ( int k = j + 1 ; k < arr . Count ; k ++ ) { if ( arr [ j ] + arr [ k ] == i ) { count ++ ; } if ( count > 1 ) break ; } if ( count > 1 ) break ; } if ( count == 1 ) { arr . Add ( i ) ; } } } public static void Main ( String [ ] args ) { ulam ( ) ; int n = 9 ; Console . WriteLine ( arr [ n - 1 ] ) ; } }
Find the number of rectangles of size 2 * 1 which can be placed inside a rectangle of size n * m | C # program to Find the number of rectangles of size 2 * 1 can be placed inside a rectangle of size n * m ; function to Find the number of rectangles of size 2 * 1 can be placed inside a rectangle of size n * m ; if n is even ; if m is even ; if both are odd ; Driver Code ; function call
using System ; class GFG { static int NumberOfRectangles ( int n , int m ) { if ( n % 2 == 0 ) return ( n / 2 ) * m ; else if ( m % 2 == 0 ) return ( m / 2 ) * n ; return ( n * m - 1 ) / 2 ; } public static void Main ( ) { int n = 3 , m = 3 ; Console . WriteLine ( NumberOfRectangles ( n , m ) ) ; } }
Next greater Number than N with the same quantity of digits A and B | C # program to find next greater Number than N with the same quantity of digits A and B ; Recursive function to find the required number ; If the resulting number is >= n and count of a = count of b , return the number ; select minimum of two and call the function again ; Function to find the number next greater Number than N with the same quantity of digits A and B ; Driver code
using System ; class GFG { static long findNumUtil ( long res , int a , int aCount , int b , int bCount , int n ) { if ( res > 1e11 ) return ( long ) 1e11 ; if ( aCount == bCount && res >= n ) return res ; return Math . Min ( findNumUtil ( res * 10 + a , a , aCount + 1 , b , bCount , n ) , findNumUtil ( res * 10 + b , a , aCount , b , bCount + 1 , n ) ) ; } static int findNum ( int n , int a , int b ) { int result = 0 ; int aCount = 0 ; int bCount = 0 ; return ( int ) findNumUtil ( result , a , aCount , b , bCount , n ) ; } public static void Main ( ) { int N = 4500 ; int A = 4 ; int B = 7 ; Console . WriteLine ( findNum ( N , A , B ) ) ; } }
Minimum and maximum number of N chocolates after distribution among K students | C # implementation of the above approach ; Driver code
using System ; class GFG { public static void Main ( ) { int n = 7 ; int k = 3 ; if ( n % k == 0 ) Console . WriteLine ( n / k + " ▁ " + n / k ) ; else Console . WriteLine ( ( n - ( n % k ) ) / k + " ▁ " + ( ( ( n - ( n % k ) ) / k ) + 1 ) ) ; } }
Total money to be paid after traveling the given number of hours | C # implementation of the above approach ; calculating hours travelled
using System ; class GFG { public static void Main ( ) { float m = 50 , n = 5 , x = 67 , h = 2927 ; int z = ( int ) ( Math . Ceiling ( ( h / 60 * 1.0 ) ) ) ; if ( z <= n ) Console . WriteLine ( z * m ) ; else Console . WriteLine ( n * m + ( z - n ) * x ) ; } }
Absolute difference between sum and product of roots of a quartic equation | C # implementation of above approach ; Function taking coefficient of each term of equation as input ; Finding sum of roots ; Finding product of roots ; Absolute difference ; Driver Code
using System ; class GFG { static double sumProductDifference ( int a , int b , int c , int d , int e ) { double rootSum = ( double ) ( - 1 * b ) / a ; double rootProduct = ( double ) e / a ; return Math . Abs ( rootSum - rootProduct ) ; } public static void Main ( ) { Console . Write ( sumProductDifference ( 8 , 4 , 6 , 4 , 1 ) ) ; } }
Number of solutions of n = x + n âŠ • x | C # implementation of above approach ; Function to find the number of solutions of n = n xor x ; Counter to store the number of solutions found ; Driver code
using System ; class GFG { static int numberOfSolutions ( int n ) { int c = 0 ; for ( int x = 0 ; x <= n ; ++ x ) if ( n == x + ( n ^ x ) ) ++ c ; return c ; } public static void Main ( ) { int n = 3 ; Console . Write ( numberOfSolutions ( n ) ) ; } }
Program to find minimum number of lectures to attend to maintain 75 % | C # Program to find minimum number of lectures to attend to maintain 75 % attendance ; Method to compute minimum lecture ; Formula to compute ; Driver Code
using System ; class GFG { static int minimumLectures ( int m , int n ) { int ans = 0 ; if ( n < ( int ) Math . Ceiling ( 0.75 * m ) ) ans = ( int ) Math . Ceiling ( ( ( 0.75 * m ) - n ) / 0.25 ) ; else ans = 0 ; return ans ; } public static void Main ( ) { int M = 9 , N = 1 ; Console . WriteLine ( minimumLectures ( M , N ) ) ; } }
Count Numbers with N digits which consists of odd 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 int countNumbers ( int N ) { return ( int ) ( Math . Pow ( 10 , N ) - Math . Pow ( 8 , N ) ) / 2 ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( countNumbers ( n ) ) ; } }
Sum of all Primes in a given range using Sieve of Eratosthenes | C # program to find sum of primes in range L to R ; prefix [ i ] is going to store sum of primes till i ( including i ) . ; Function to build the prefix sum array ; Create a boolean array " prime [ 0 . . n ] " . A value in prime [ i ] will finally be false if i is Not a prime , else true . ; If prime [ p ] is not changed , then it is a prime ; Update all multiples of p ; Build prefix array ; Function to return sum of prime in range ; Driver code
using System ; class GFG { static int MAX = 10000 ; static int [ ] prefix = new int [ MAX + 1 ] ; static void buildPrefix ( ) { bool [ ] prime = new bool [ MAX + 1 ] ; for ( int i = 0 ; i < MAX + 1 ; i ++ ) prime [ i ] = true ; for ( int p = 2 ; p * p <= MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= MAX ; i += p ) prime [ i ] = false ; } } prefix [ 0 ] = prefix [ 1 ] = 0 ; for ( int p = 2 ; p <= MAX ; p ++ ) { prefix [ p ] = prefix [ p - 1 ] ; if ( prime [ p ] == true ) prefix [ p ] += p ; } } static int sumPrimeRange ( int L , int R ) { buildPrefix ( ) ; return prefix [ R ] - prefix [ L - 1 ] ; } public static void Main ( ) { int L = 10 , R = 20 ; Console . WriteLine ( sumPrimeRange ( L , R ) ) ; } }
Sum of the first N terms of the series 5 , 12 , 23 , 38. ... | C # program to find sum of first n terms ; Function to calculate the sum ; Driver code ; number of terms to be included in sum ; find the Sn
using System ; class GFG { static int calculateSum ( int n ) { return 2 * ( n * ( n + 1 ) * ( 2 * n + 1 ) / 6 ) + n * ( n + 1 ) / 2 + 2 * ( n ) ; } public static void Main ( ) { int n = 3 ; Console . WriteLine ( " Sum ▁ = ▁ " + calculateSum ( n ) ) ; } }
Program to find number of solutions in Quadratic Equation | C # Program to find the solutions of specified equations ; Method to check for solutions of equations ; If the expression is greater than 0 , then 2 solutions ; If the expression is equal to 0 , then 2 solutions ; Else no solutions ; Driver Code
using System ; class GFG { static void checkSolution ( int a , int b , int c ) { if ( ( ( b * b ) - ( 4 * a * c ) ) > 0 ) Console . WriteLine ( "2 ▁ solutions " ) ; else if ( ( ( b * b ) - ( 4 * a * c ) ) == 0 ) Console . WriteLine ( "1 ▁ solution " ) ; else Console . WriteLine ( " No ▁ solutions " ) ; } public static void Main ( ) { int a = 2 , b = 5 , c = 2 ; checkSolution ( a , b , c ) ; } }