#include #include using namespace std; using namespace atcoder; using ll = long long; void fast_io() { cin.tie(nullptr); ios_base::sync_with_stdio(false); } int main(void) { fast_io(); ll l, r, c; cin >> l >> r >> c; ll ans = 1000; for (ll i = l; i <= min(r, l + 1000); i++) { ll q = c * i / 1000; ll x = 1000 * q - c * i; if (x < 0) x += 1000; ans = min(ans, x); } cout << ans << endl; return 0; }