-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.cpp
More file actions
28 lines (23 loc) · 1.06 KB
/
1.cpp
File metadata and controls
28 lines (23 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//******************************************* PROBLEM NO: 1 ***************************************//
// //
// If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. //
// The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. //
// //
//*****************************************************************************************************//
#include<iostream>
using namespace std;
long long sumOfMultiples(long long m, long long N);
int main()
{
long long sum = sumOfMultiples(3,999)
+ sumOfMultiples(5,999)
- sumOfMultiples(15,999);
cout<<sum<<endl;
return 0;
}
// Gives sum of all multiples of m that are less than or equal to N
long long sumOfMultiples(long long m, long long N)
{
long long n = N/m;
return m*((n*(n + 1))/2);
}