Skip to content

Files

Latest commit

Aug 16, 2024
5575415 · Aug 16, 2024

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Nov 26, 2023
Aug 16, 2024
Nov 26, 2023
Feb 8, 2024

Sum of multiples


Given are two positive integers a and b . The output of your program should be the sum of all the multiples of a and b below a given positive integer n 10 11 .

For example, if a = 5 , b = 7 and n = 50 , then the output should be 386 , because the sum of all the multiples of 5 and 7 below 50 is:

5 + 7 + 10 + 14 + 15 + 20 + 21 + 25
+ 28 + 30 + 35 + 40 + 42 + 45 + 49 = 386

For a = 3 , b = 2 and n = 30 , the output should equal 285 , since the sum of all the multiples of 3 and 2 below 30 is:

2 + 3 + 4 + 6 + 8 + 9 + 10 + 12 + 14
+ 15 + 16 + 18 + 20 + 21 + 22 + 24
+ 26 + 27 + 28 = 285

The input consists of three positive integers a , b and n separated by a space. The output should be a single positive integer representing the sum of all the multiples of a and b below n .

Note that the numbers may become very large. You should use a data type that can handle numbers as large as 10 19 .