#include using namespace std; using ll = long long; using Graph = vector>; long long primeNumber(long long x) { bool fire = true; for(int i = 2; i <= sqrt(x); i++) { if(x % i == 0) { fire = false; } } return fire; } int main() { long long L,R,C; cin >> L >> R >> C; long long ans = 1ll << 60ll; int count = 0; for(int i = L; i <= R; i++) { long long X = i * C; long long A = 1000 - (X % 1000); ans = min(ans,A); count++; if(count >= 1500) { break; } } cout << ans << endl; }