반응형
Your Job
Find the sum of all multiples of n
below m
Keep in Mind
n
andm
are natural numbers (positive integers)m
is excluded from the multiples
Examples
sumMul(2, 9) ==> 2 + 4 + 6 + 8 = 20
sumMul(3, 13) ==> 3 + 6 + 9 + 12 = 30
sumMul(4, 123) ==> 4 + 8 + 12 + ... = 1860
sumMul(4, -7) ==> "INVALID"
Solution:
def invalid_value(func):
def wrapper(n, m):
return (n<1 or m<1) and "INVALID" or func(n, m)
return wrapper
@invalid_value
def sum_mul(n, m):
return sum(range(0, m, n))
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1114. Exclamation marks series #6: Remove n exclamation marks in the sentence from left to right (0) | 2022.11.14 |
---|---|
1113. Parse nice int from char problem (0) | 2022.11.13 |
1111. Grasshopper - Debug sayHello (0) | 2022.11.12 |
1110. No oddities here (0) | 2022.11.10 |
1109. Sentence Smash (0) | 2022.11.09 |