L, R, M = map(int, input().split()) l = [i for i in range(L, R+1)] ans = 0 for i in l: ans += i % M print(ans)