l,r,c = map(int,input().split()) ans = int(1e18) for i in range(l,r+1): ans = min(ans,c*i%1000) if i > l+1000: break print(ans)