#include using namespace std; #ifdef _RUTHEN #include #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template using V = vector; int main() { ios::sync_with_stdio(false); cin.tie(0); long long L, R, C; cin >> L >> R >> C; long long ans = 1LL << 60; for (long long x = L; x <= min(L + 1000000, R); x++) { if (C * x % 1000 == 0) { ans = 0; } else { ans = min(ans, 1000 - C * x % 1000); } } cout << ans << '\n'; return 0; }