18 lines
No EOL
648 B
C
18 lines
No EOL
648 B
C
#include <cstddef>
|
|
|
|
/**
|
|
This function returns the sum of all positive integers less or equal n which are a multiples of 3 or of 5, WITH using a loop.
|
|
@param[in] n
|
|
@param[out] M
|
|
*/
|
|
size_t special_sum_loop(size_t n);
|
|
|
|
|
|
/**
|
|
This function returns the sum of all positive integers less or equal n which are a multiples of 3 or of 5, WITHOUT using a loop.
|
|
Example: For n=15, we have 60 = 3+5+6+9+10+12+15 = (1+2+3+4+5)*3 + (1+2+3)*5 - 1*15
|
|
Formula: M = (\sum_{i=1}^{k_3} i)*3 + (\sum_{i=1}^{k_5} i)*5 - (\sum_{i=1}^{k_15} i)*15
|
|
@param[in] n
|
|
@param[out] M
|
|
*/
|
|
size_t special_sum_noloop(size_t n); |