#include #include #include #include #include #include #include #include #include #include using ll = long long; using namespace std; int main() { ll l, r, c, rest = 0, min1 = 1001; cin >> l >> r >> c; set st; for (ll i = l; i <= r; i++){ rest = 1000 - i*c%1000; if (rest == 1000){ cout << 0 << endl; return 0; } min1 = min(min1, rest); if (!st.count(rest)) st.insert(rest); else { cout << min1 << endl; return 0; } } cout << min1 << endl; }