#include #include using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; using dl = double long; using Graph = vector >; using mint = modint998244353; const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e+18; #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP2(i, s, n) for (int i = (s); i < (int)(n); i++) #define REPB(i,n) for(int i = n-1; (int)i >= 0; --i) #define FOREACH(x,a) for(auto& (x) : (a) #define YESNO(T) if(T){cout<<"YES"< #define VL vector #define VS vector #define VC vector #define VVI vector > #define VVL vector > #define VVC vector > #define VPII vector > #define VPLL vector > #define VPSI vector > template inline void printVec(std::vector v){ REP(i,v.size()){ if(i) std::cout << " "; std::cout << v[i]; } std::cout << std::endl; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll l,r,c; cin >> l >> r >> c; ll d; VL ans; ll sc = c; c = l * c; REP2(i,l,min(r + 1,l + 1010)){ d = c % 1000; if(d == 0) { // cout << 0 << " " << c << endl; ans.push_back(0); } else { // cout << 1000 - d << " " << c << endl; ans.push_back(1000 - d); } c += sc; } // printVec(ans); sort(ALL(ans)); cout << ans[0] << endl; return 0; }