Search
 
SCRIPT & CODE EXAMPLE
 

C

find sum of multiples of a number up to N

// C# program to find sum of multiples
// of a number up to N efficiently
using System;
 
class GFG {
 
    // Function for calculating sum
    // of multiples of a upto N
    static int calculate_sum(int a, int N)
    {
 
        // Number of multiples
        int m = N / a;
 
        // sum of first m natural numbers
        int sum = m * (m + 1) / 2;
 
        // sum of multiples
        int ans = a * sum;
 
        return ans;
    }
 
    // Driver code
    public static void Main()
    {
 
        int a = 7, N = 49;
        Console.WriteLine("Sum of multiples of " + a +
         " up to " + N + " = " + calculate_sum(a, N));
    }
}
Comment

PREVIOUS NEXT
Code Example
C :: print ascii value in c 
C :: execute maven project in cmd 
C :: fast inverse square root explained 
C :: program execution time calculate in c 
C :: que es % en c 
C :: c program 
C :: how to print a file c 
C :: c int to string 
C :: c how to check a palindrome string 
C :: c style array 
C :: get range of values in mongodb 
C :: write array of char to file in c 
C :: uuidv4 javascript 
C :: c string 
C :: slug urls django 
C :: 2 bytes integer c 
C :: double array in c 
C :: #define arduino 
C :: print variable adress c 
C :: how to add 1 to 10 in c 
C :: c typedef 
C :: gcd and lcd in c 
C :: casting in c 
C :: KneesDev 
C :: powershell search big files 
C :: how to print % in c 
C :: how to read from a file in c 
C :: how to print logs when doing unit-testing in rust 
C :: linear and binary search 
C :: allintext:christie kiser filetype:log 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =