#include #include using namespace std; int main() { int l, r, c; cin >> l >> r >> c; int res = 1000; for (int i = l; i <= r; i++) { res = min(res, 1000 - ((i * c) % 1000)); if (i * c % 1000 == 0) res = 0; } cout << res << endl; }