import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) mod = 998244353 def floor_sum(n,m,a,b): ans=0 if a>=m: ans+=(n-1)*n*(a//m)//2 a%=m if b>=m: ans+=n*(b//m) b%=m y_max=(a*n+b)//m x_max=(y_max*m-b) if y_max==0: return ans ans+=(n-(x_max+a-1)//a)*y_max ans+=floor_sum(y_max,a,m,(a-x_max%a)%a) return ans def mod_le(n, a, b, k, m): #0 <= x < n について、 (a * x + b) mod m < k なるものの個数を求める return floor_sum(n, m, a, b + m) - floor_sum(n, m, a, b - k + m) for _ in range(1): l, r, c = mi() n = r - l + 1 m = 1000 a = (- c) % m b = (1000 - l * c) % m if a == 0: print(b % m) continue ok = m ng = 0 while abs(ok - ng) > 1: mid = (ok + ng) // 2 if mod_le(n, a, b, mid, m): ok = mid else: ng = mid print(ok - 1)