num_list = list(map(int, input().split())) L, R, M = num_list[0], num_list[1], num_list[2] remainder_list = [] remainder_count = 0 if L == R: remainder_count = 1 else: for i in range(L, R + 1): rem = i % M if rem not in remainder_list: remainder_list.append(rem) remainder_count += len(remainder_list) print(remainder_count)