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