https://www.codewars.com/kata/54c2fc0552791928c9000517
문제
Write this function
for i from 1 to n, do i % m and return the sum
f(n=10, m=5) // returns 20 (1+2+3+4+0 + 1+2+3+4+0)
You'll need to get a little clever with performance, since n can be a very large number
코드
def f(n, m):
t = 0
for i in range(m):
t += i
t = (n//m)*t
for j in range(n%m+1):
t += j
return t
def f(n, m):
t = (int((m-1)*m/2))*(n//m)
s = n%m+1
t += int((s-1)*s/2)
return t
설명