#include using namespace std; int main() { int L, R, C, A; A = 999; cin >> L >> R >> C; int l = L - L / 1000*1000; int r = R - R / 1000 * 1000; int c = C - C / 1000*1000; if (R - L > 1000) { r = l + 999; } else { r = l + (R - L); } for (int i = l; i < r+1; i++) { if (A > ((i * c - 1) / 1000 + 1) * 1000 - i * c) { A = ((i * c - 1) / 1000 + 1) * 1000 - i * c; } //cout << l << " " << c << " " << ((i * c - 1) / 1000 + 1) << " " << A << endl; } if (A == 1000) { A = 0; } cout << A << endl; return 0; }