codeparrot/xlcost-text-to-code huggingface dataset:
Check whether the given number is Euclid Number or not | C # implementation of the approach ; Function to generate the Prime numbers and store their products ; 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 ; Update all multiples of p ; store prefix product of prime numbers to unordered_set ' s ' ; update product by multiplying next prime ; insert ' produc + 1' to set ; Function to check the number for Euclid Number ; Check if number exist in unordered set or not If exist , return true ; Driver code ; Get the prime numbers ; Get n ; Check if n is Euclid Number ; Get n ; Check if n is Euclid Number
using System ; using System . Collections . Generic ; class GFG { static int MAX = 10000 ; static HashSet < int > s = new HashSet < int > ( ) ; static void SieveOfEratosthenes ( ) { Boolean [ ] prime = new Boolean [ MAX ] ; for ( int p = 0 ; p < MAX ; p ++ ) prime [ p ] = true ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p < MAX ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i < MAX ; i += p ) prime [ i ] = false ; } } int product = 1 ; for ( int p = 2 ; p < MAX ; p ++ ) { if ( prime [ p ] ) { product = product * p ; s . Add ( product + 1 ) ; } } } static Boolean isEuclid ( int n ) { if ( s . Contains ( n ) ) return true ; else return false ; } public static void Main ( String [ ] args ) { SieveOfEratosthenes ( ) ; int n = 31 ; if ( isEuclid ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; n = 42 ; if ( isEuclid ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Check whether the given number is Wagstaff prime or not | C # program to check if a number is Wagstaff prime or not ; Function to check if a number is prime or not ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; Utility function to check power of two ; Driver Code ; Check if number is prime and of the form ( 2 ^ q + 1 ) / 3
using System ; 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 bool isPowerOfTwo ( int n ) { return n != 0 && ( ( n & ( n - 1 ) ) == 0 ) ; } public static void Main ( ) { int n = 43 ; if ( isPrime ( n ) && ( isPowerOfTwo ( n * 3 - 1 ) ) ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } }
Area of a square inscribed in a circle which is inscribed in a hexagon | C # Program to find the area of the square inscribed within the circle which in turn is inscribed in a hexagon ; Function to find the area of the square ; side of hexagon cannot be negative ; area of the square ; Driver code
using System ; class GFG { static float area ( float a ) { if ( a < 0 ) return - 1 ; float area = ( float ) Math . Pow ( ( a * Math . Sqrt ( 3 ) ) / ( Math . Sqrt ( 2 ) ) , 2 ) ; return area ; } public static void Main ( ) { float a = 5 ; Console . WriteLine ( area ( a ) ) ; } }
Program to find Nth term of series 1 , 6 , 17 , 34 , 56 , 86 , 121 , 162 , ... ... . | C # program to find the N - th term of the series : 1 , 6 , 17 , 34 , 56 , 86 , 121 , 162 , ... . . ; calculate Nth term of series ; Driver code
using System ; class GFG { static int nthTerm ( int n ) { return 3 * ( int ) Math . Pow ( n , 2 ) - 4 * n + 2 ; } public static void Main ( ) { int N = 4 ; Console . Write ( nthTerm ( N ) ) ; } }
Sum of the first N terms of the series 2 , 10 , 30 , 68 , ... . | 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 Sum
using System ; class gfg { public void calculateSum ( int n ) { double r = ( n * ( n + 1 ) / 2 + Math . Pow ( ( n * ( n + 1 ) / 2 ) , 2 ) ) ; Console . WriteLine ( " Sum ▁ = ▁ " + r ) ; } public static int Main ( ) { gfg g = new gfg ( ) ; int n = 3 ; g . calculateSum ( n ) ; Console . Read ( ) ; return 0 ; } }
Check if two arrays are permutations of each other using Mathematical Operation | C # code to check if arrays are permutations of eah other ; Function to check if arrays are permutations of each other . ; Calculating sum and multiply of first array ; Calculating sum and multiply of second array ; If sum and mul of both arrays are equal , return true , else return false . ; Driver code
using System ; class GFG { static bool arePermutations ( int [ ] a , int [ ] b , int n , int m ) { int sum1 = 0 , sum2 = 0 , mul1 = 1 , mul2 = 1 ; for ( int i = 0 ; i < n ; i ++ ) { sum1 += a [ i ] ; mul1 *= a [ i ] ; } for ( int i = 0 ; i < m ; i ++ ) { sum2 += b [ i ] ; mul2 *= b [ i ] ; } return ( ( sum1 == sum2 ) && ( mul1 == mul2 ) ) ; } public static void Main ( ) { int [ ] a = { 1 , 3 , 2 } ; int [ ] b = { 3 , 1 , 2 } ; int n = a . Length ; int m = b . Length ; if ( arePermutations ( a , b , n , m ) == true ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }
Program to find the head start in a race | C # implementation of above approach ; Function to find the B start to C ; When B completed it 's 100 meter  then Completed meters by C is ; Driver Code ; When A completed it 's 100 meter  Then completed meters of B and C is
using System ; class GFG { static int Race ( int B , int C ) { int result = 0 ; result = ( ( C * 100 ) / B ) ; return 100 - result ; } public static void Main ( ) { int B = 10 ; int C = 28 ; B = 100 - B ; C = 100 - C ; Console . Write ( Race ( B , C ) + " ▁ meters " ) ; } }
Minimum time required to fill a cistern using N pipes | C # implementation of above approach ; Function to calculate the time ; Driver Code
using System ; class GFG { static float Time ( float [ ] arr , int n , float Emptypipe ) { float fill = 0 ; for ( int i = 0 ; i < n ; i ++ ) fill += 1 / arr [ i ] ; fill = fill - ( 1 / ( float ) Emptypipe ) ; return 1 / fill ; } public static void Main ( ) { float [ ] arr = { 12 , 14 } ; float Emptypipe = 30 ; int n = arr . Length ; Console . WriteLine ( ( int ) ( Time ( arr , n , Emptypipe ) ) + " ▁ Hours " ) ; } }
Check if Decimal representation of an Octal number is divisible by 7 | C # program to check if Decimal representation of an Octal number is divisible by 7 or not ; Function to check Divisibility ; Sum of all individual digits ; Condition ; Driver Code ; Octal number
using System ; class GFG { static int check ( int n ) { int sum = 0 ; while ( n != 0 ) { sum += n % 10 ; n = n / 10 ; } if ( sum % 7 == 0 ) return 1 ; else return 0 ; } public static void Main ( String [ ] args ) { int n = 25 ; String s = ( check ( n ) == 1 ) ? " YES " : " NO " ; Console . WriteLine ( s ) ; } }
Sum of all the prime divisors of a number | C # program to find sum of prime divisors of N ; Function to check if the number is prime or not . ; Corner cases ; This is checked so that we can skip middle five numbers in below loop ; function to find sum of prime divisors of N ; Driver code
using System ; 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 int SumOfPrimeDivisors ( int n ) { int sum = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( n % i == 0 ) { if ( isPrime ( i ) ) sum += i ; } } return sum ; } public static void Main ( ) { int n = 60 ; Console . WriteLine ( " Sum ▁ of ▁ prime ▁ divisors ▁ of ▁ 60 ▁ is ▁ " + SumOfPrimeDivisors ( n ) + " STRNEWLINE " ) ; } }
Sum of all the prime divisors of a number | C # program to find prime divisors of all numbers from 1 to n ; function to find prime divisors of all numbers from 1 to n ; if the number is prime ; add this prime to all it 's multiples ; Driver code
using System ; class GFG { static int Sum ( int N ) { int [ ] SumOfPrimeDivisors = new int [ N + 1 ] ; for ( int i = 2 ; i <= N ; ++ i ) { if ( SumOfPrimeDivisors [ i ] == 0 ) { for ( int j = i ; j <= N ; j += i ) { SumOfPrimeDivisors [ j ] += i ; } } } return SumOfPrimeDivisors [ N ] ; } public static void Main ( ) { int N = 60 ; Console . Write ( " Sum ▁ of ▁ prime ▁ " + " divisors ▁ of ▁ 60 ▁ is ▁ " + Sum ( N ) + " STRNEWLINE " ) ; } }
Find ( a ^ b ) % m where ' b ' is very large | C # program to find ( a ^ b ) % m for b very large . ; Function to find power ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with the result ; y must be even now y = y >> 1 ; y = y / 2 ; Driver Code ; String input as b is very large ; Reduce the number B to a small number using Fermat Little
using System ; class GFG { static long power ( long x , long y , long p ) { long res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) > 0 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } public static void Main ( ) { long a = 3 ; string b = "100000000000000000000000000" ; long remainderB = 0 ; long MOD = 1000000007 ; for ( int i = 0 ; i < b . Length ; i ++ ) remainderB = ( remainderB * 10 + b [ i ] - '0' ) % ( MOD - 1 ) ; Console . WriteLine ( power ( a , remainderB , MOD ) ) ; } }
Squares of numbers with repeated single digits | Set 1 ( 3 , 6 and 9 ) | C # program to find square of these large numbers ; Function to find the square of 333. . .333 , 666. . .666 and 999. . .999 ; if the number is 333. . .333 ; if the number is 666. . .666 ; if the number is 999. . .999 ; variable for hold result ; find the no of digit ; add size - 1 time a in result ; add one time b in result ; add size - 1 time c in result ; add one time d in result ; return result ; Drivers code ; find square of 33. .33 ; find square of 66. .66 ; find square of 66. .66
using System ; class GFG { static string find_Square_369 ( string num ) { char a , b , c , d ; if ( num [ 0 ] == '3' ) { a = '1' ; b = '0' ; c = '8' ; d = '9' ; } else if ( num [ 0 ] == '6' ) { a = '4' ; b = '3' ; c = '5' ; d = '6' ; } else { a = '9' ; b = '8' ; c = '0' ; d = '1' ; } string result = " " ; int size = num . Length ; for ( int i = 1 ; i < size ; i ++ ) result += a ; result += b ; for ( int i = 1 ; i < size ; i ++ ) result += c ; result += d ; return result ; } public static void Main ( ) { string num_3 , num_6 , num_9 ; num_3 = "3333" ; num_6 = "6666" ; num_9 = "9999" ; string result = " " ; result = find_Square_369 ( num_3 ) ; Console . Write ( " Square ▁ of ▁ " + num_3 + " ▁ is ▁ : ▁ " + result + " STRNEWLINE " ) ; result = find_Square_369 ( num_6 ) ; Console . Write ( " Square ▁ of ▁ " + num_9 + " ▁ is ▁ : ▁ " + result + " STRNEWLINE " ) ; result = find_Square_369 ( num_9 ) ; Console . Write ( " Square ▁ of ▁ " + num_9 + " ▁ is ▁ : ▁ " + result + " STRNEWLINE " ) ; } }
Trick for modular division ( ( x1 * x2 ... . xn ) / b ) mod ( m ) |
using System ; class GFG { public static void Main ( ) { long ans = 1 ; long mod = ( long ) 1000000007 * 120 ; for ( int i = 0 ; i < 5 ; i ++ ) ans = ( ans * ( 55555 - i ) ) % mod ; ans = ans / 120 ; Console . Write ( " Answer ▁ using ▁ " + " shortcut : ▁ " + ans ) ; } }
Ways to multiply n elements with an associative operation | C # code to find number of ways to multiply n elements with an associative operation ; Function to find the required factorial ; Function to find nCr ; function to find the number of ways ; Driver Code
using System ; class GFG { static int fact ( int n ) { if ( n == 0 n == 1 ) return 1 ; int ans = 1 ; for ( int i = 1 ; i <= n ; i ++ ) ans = ans * i ; return ans ; } static int nCr ( int n , int r ) { int Nr = n , Dr = 1 , ans = 1 ; for ( int i = 1 ; i <= r ; i ++ ) { ans = ( ans * Nr ) / ( Dr ) ; Nr -- ; Dr ++ ; } return ans ; } static int solve ( int n ) { int N = 2 * n - 2 ; int R = n - 1 ; return nCr ( N , R ) * fact ( n - 1 ) ; } public static void Main ( ) { int n = 6 ; Console . WriteLine ( solve ( n ) ) ; } }
Pythagorean Triplet with given sum | C # program to find Pythagorean Triplet of given sum . ; Considering triplets in sorted order . The value of first element in sorted triplet can be at - most n / 3. ; The value of second element must be less than equal to n / 2 ; Driver Code
using System ; class GFG { static void pythagoreanTriplet ( int n ) { for ( int i = 1 ; i <= n / 3 ; i ++ ) { for ( int j = i + 1 ; j <= n / 2 ; j ++ ) { int k = n - i - j ; if ( i * i + j * j == k * k ) { Console . Write ( i + " , ▁ " + j + " , ▁ " + k ) ; return ; } } } Console . Write ( " No ▁ Triplet " ) ; } public static void Main ( ) { int n = 12 ; pythagoreanTriplet ( n ) ; } }
Program to print binomial expansion series | C # program to print terms of binomial series and also calculate sum of series . ; function to calculate factorial of a number ; function to print the series ; calculating the value of n ! ; loop to display the series ; For calculating the value of nCr ; calculating the value of A to the power k and X to the power k ; display the series ; main function started
using System ; class GFG { static int factorial ( int n ) { int f = 1 ; for ( int i = 2 ; i <= n ; i ++ ) f *= i ; return f ; } static void series ( int A , int X , int n ) { int nFact = factorial ( n ) ; for ( int i = 0 ; i < n + 1 ; i ++ ) { int niFact = factorial ( n - i ) ; int iFact = factorial ( i ) ; int aPow = ( int ) Math . Pow ( A , n - i ) ; int xPow = ( int ) Math . Pow ( X , i ) ; Console . Write ( ( nFact * aPow * xPow ) / ( niFact * iFact ) + " ▁ " ) ; } } public static void Main ( ) { int A = 3 , X = 4 , n = 5 ; series ( A , X , n ) ; } }
Sum of series with alternate signed squares of AP | C # program to find sum of series with alternate signed square AP sums . ; function to calculate series sum ; Driver code
using System ; class GFG { static int seiresSum ( int n , int [ ] a ) { int res = 0 , i ; for ( i = 0 ; i < 2 * n ; i ++ ) { if ( i % 2 == 0 ) res += a [ i ] * a [ i ] ; else res -= a [ i ] * a [ i ] ; } return res ; } public static void Main ( ) { int n = 2 ; int [ ] a = { 1 , 2 , 3 , 4 } ; Console . WriteLine ( seiresSum ( n , a ) ) ; } }
Power of a prime number ‘ r ’ in n ! | C # program to find power of a prime number ' r ' in n ! ; Function to return power of a no . ' r ' in factorial of n ; Keep dividing n by powers of ' r ' and update count ; Driver code
using System ; class GFG { static int power ( int n , int r ) { int count = 0 ; for ( int i = r ; ( n / i ) >= 1 ; i = i * r ) count += n / i ; return count ; } public static void Main ( ) { int n = 6 , r = 3 ; Console . WriteLine ( power ( n , r ) ) ; } }
Average of first n odd naturals numbers | C # program to find average of sum of first n odd natural numbers . ; Returns the Avg of first n odd numbers ; sum of first n odd number ; Average of first n odd numbers ; Driver code
using System ; class GFG { static int avg_of_odd_num ( int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += ( 2 * i + 1 ) ; return sum / n ; } public static void Main ( ) { int n = 20 ; avg_of_odd_num ( n ) ; Console . Write ( avg_of_odd_num ( n ) ) ; } }
Average of first n odd naturals numbers | C # Program to find the average of sum of first n odd numbers ; Return the average of sum of first n odd numbers ; Driver Code
using System ; class GFG { static int avg_of_odd_num ( int n ) { return n ; } public static void Main ( ) { int n = 8 ; Console . Write ( avg_of_odd_num ( n ) ) ; } }
Program to print Fibonacci Triangle | C # Implementation for Fibonacci triangle ; function to fill Fibonacci Numbers in f [ ] ; 1 st and 2 nd number of the series are 1 and 1 ; Add the previous 2 numbers in the series and store it ; Fill Fibonacci numbers in f [ ] using fib ( ) . We need N = n * ( n + 1 ) / 2 Fibonacci numbers to make a triangle of height n ; To store next Fibonacci Number to print ; for loop to keep track of number of lines ; For loop to keep track of numbers in each line ; Driver code
using System ; class GFG { static void fib ( int [ ] f , int N ) { f [ 1 ] = 1 ; f [ 2 ] = 1 ; for ( int i = 3 ; i <= N ; i ++ ) f [ i ] = f [ i - 1 ] + f [ i - 2 ] ; } static void fiboTriangle ( int n ) { int N = n * ( n + 1 ) / 2 ; int [ ] f = new int [ N + 1 ] ; fib ( f , N ) ; int fiboNum = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) Console . Write ( f [ fiboNum ++ ] + " ▁ " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int n = 5 ; fiboTriangle ( n ) ; } }
Average of odd numbers till a given odd number | C # Program to find average of odd numbers till a given odd number . ; Function to calculate the average of odd numbers ; count odd numbers ; store the sum of odd numbers ; driver function
using System ; class GFG { static int averageOdd ( int n ) { if ( n % 2 == 0 ) { Console . Write ( " Invalid ▁ Input " ) ; return - 1 ; } int sum = 0 , count = 0 ; while ( n >= 1 ) { count ++ ; sum += n ; n = n - 2 ; } return sum / count ; } public static void Main ( ) { int n = 15 ; Console . Write ( averageOdd ( n ) ) ; } }
Average of odd numbers till a given odd number | C # Program to find average of odd numbers till a given odd number . ; Function to calculate the average of odd numbers ; driver function
using System ; class GFG { static int averageOdd ( int n ) { if ( n % 2 == 0 ) { Console . Write ( " Invalid ▁ Input " ) ; return - 1 ; } return ( n + 1 ) / 2 ; } public static void Main ( ) { int n = 15 ; Console . Write ( averageOdd ( n ) ) ; } }
Find max of two Rational numbers | C # program to find max between two Rational numbers ; Get lcm of two number 's ; Get max rational number ; Find the LCM of first . denominator and sec . denominator ; Declare nume1 and nume2 for get the value of first numerator and second numerator ; Driver Code
using System ; class GFG { class Rational { public int nume , deno ; public Rational ( int nume , int deno ) { this . nume = nume ; this . deno = deno ; } } ; static int lcm ( int a , int b ) { return ( a * b ) / ( __gcd ( a , b ) ) ; } static Rational maxRational ( Rational first , Rational sec ) { int k = lcm ( first . deno , sec . deno ) ; int nume1 = first . nume ; int nume2 = sec . nume ; nume1 *= k / ( first . deno ) ; nume2 *= k / ( sec . deno ) ; return ( nume2 < nume1 ) ? first : sec ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void Main ( String [ ] args ) { Rational first = new Rational ( 3 , 2 ) ; Rational sec = new Rational ( 3 , 4 ) ; Rational res = maxRational ( first , sec ) ; Console . Write ( res . nume + " / " + res . deno ) ; } }
Trinomial Triangle | C # Program to print trinomial triangle . ; Function to find the trinomial triangle value . ; base case ; base case ; recursive step . ; Function to print Trinomial Triangle of height n . ; printing n rows . ; printing first half of triangle ; printing second half of triangle . ; Driver function
using System ; public class GfG { public static int TrinomialValue ( int n , int k ) { if ( n == 0 && k == 0 ) return 1 ; if ( k < - n k > n ) return 0 ; return TrinomialValue ( n - 1 , k - 1 ) + TrinomialValue ( n - 1 , k ) + TrinomialValue ( n - 1 , k + 1 ) ; } public static void printTrinomial ( int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = - i ; j <= 0 ; j ++ ) Console . Write ( TrinomialValue ( i , j ) + " ▁ " ) ; for ( int j = 1 ; j <= i ; j ++ ) Console . Write ( TrinomialValue ( i , j ) + " ▁ " ) ; Console . WriteLine ( ) ; } } public static void Main ( ) { int n = 4 ; printTrinomial ( n ) ; } }
Trinomial Triangle | C # Program to print trinomial triangle . ; Function to find the trinomial triangle value . ; Using property of trinomial triangle . ; If value already calculated , return that . ; base case ; base case ; recursive step and storing the value . ; Function to print Trinomial Triangle of height n . ; printing n rows . ; printing first half of triangle ; printing second half of triangle . ; Driver Code
using System ; class GFG { private static int MAX = 10 ; public static int TrinomialValue ( int [ , ] dp , int n , int k ) { if ( k < 0 ) k = - k ; if ( dp [ n , k ] != 0 ) return dp [ n , k ] ; if ( n == 0 && k == 0 ) return 1 ; if ( k < - n k > n ) return 0 ; return ( dp [ n , k ] = TrinomialValue ( dp , n - 1 , k - 1 ) + TrinomialValue ( dp , n - 1 , k ) + TrinomialValue ( dp , n - 1 , k + 1 ) ) ; } public static void printTrinomial ( int n ) { int [ , ] dp = new int [ MAX , MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = - i ; j <= 0 ; j ++ ) Console . Write ( TrinomialValue ( dp , i , j ) + " ▁ " ) ; for ( int j = 1 ; j <= i ; j ++ ) Console . Write ( TrinomialValue ( dp , i , j ) + " ▁ " ) ; Console . WriteLine ( ) ; } } static public void Main ( ) { int n = 4 ; printTrinomial ( n ) ; } }
Sum of largest prime factor of each number less than equal to n | C # implementation to find sum of largest prime factor of each number less than equal to n ; function to find sum of largest prime factorof each number less than equal to n ; Create an integer array " prime [ 0 . . n ] " and initialize all entries of it as 0. A value in prime [ i ] will finally be 0 if ' i ' is a prime , else it will contain the largest prime factor of ' i ' . ; If prime [ p ] is '0' , then it is a prime number ; Update all multiples of p ; Sum up the largest prime factor of all the numbers ; if ' p ' is a non - prime number then prime [ p ] gives its largesr prime factor ; ' p ' is a prime number ; required sum ; Driver program
using System ; class GFG { static int sumOfLargePrimeFactor ( int n ) { int [ ] prime = new int [ n + 1 ] ; int sum = 0 ; for ( int i = 1 ; i < n + 1 ; i ++ ) prime [ i ] = 0 ; int max = n / 2 ; for ( int p = 2 ; p <= max ; p ++ ) { if ( prime [ p ] == 0 ) { for ( int i = p * 2 ; i <= n ; i += p ) prime [ i ] = p ; } } for ( int p = 2 ; p <= n ; p ++ ) { if ( prime [ p ] != 0 ) sum += prime [ p ] ; else sum += p ; } return sum ; } public static void Main ( ) { int n = 12 ; Console . WriteLine ( " Sum ▁ = ▁ " + sumOfLargePrimeFactor ( n ) ) ; } }
Sum of multiples of a number up to N | C # program to find sum of multiples of a number up to N efficiently ; Function for calculating sum of multiples of a upto N ; Number of multiples ; sum of first m natural numbers ; sum of multiples ; Driver code
using System ; class GFG { static int calculate_sum ( int a , int N ) { int m = N / a ; int sum = m * ( m + 1 ) / 2 ; int ans = a * sum ; return ans ; } public static void Main ( ) { int a = 7 , N = 49 ; Console . WriteLine ( " Sum ▁ of ▁ multiples ▁ of ▁ " + a + " ▁ up ▁ to ▁ " + N + " ▁ = ▁ " + calculate_sum ( a , N ) ) ; } }