18 lines
477 B
C++
18 lines
477 B
C++
/** 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 "0.hpp"
|
|
|
|
const int _a = 3;
|
|
const int _b = 5;
|
|
const int _max = 1000;
|
|
|
|
int main()
|
|
{
|
|
int total = 0;
|
|
for(int i = 1; i < 1000; i++) // 循环体
|
|
if(i % _a == 0 || i % _b == 0) total += i; // 满足条件的数字加入到 total 中
|
|
cout << total << endl;
|
|
return 0;
|
|
}
|