fef841b401 2020-08-01 kinaba: #include <iostream> fef841b401 2020-08-01 kinaba: #include <sstream> fef841b401 2020-08-01 kinaba: #include <iomanip> fef841b401 2020-08-01 kinaba: #include <vector> fef841b401 2020-08-01 kinaba: #include <string> fef841b401 2020-08-01 kinaba: #include <map> fef841b401 2020-08-01 kinaba: #include <set> fef841b401 2020-08-01 kinaba: #include <algorithm> fef841b401 2020-08-01 kinaba: #include <numeric> fef841b401 2020-08-01 kinaba: #include <iterator> fef841b401 2020-08-01 kinaba: #include <functional> fef841b401 2020-08-01 kinaba: #include <complex> fef841b401 2020-08-01 kinaba: #include <queue> fef841b401 2020-08-01 kinaba: #include <stack> fef841b401 2020-08-01 kinaba: #include <cmath> fef841b401 2020-08-01 kinaba: #include <cassert> fef841b401 2020-08-01 kinaba: #include <tuple> fef841b401 2020-08-01 kinaba: using namespace std; fef841b401 2020-08-01 kinaba: typedef long long LL; fef841b401 2020-08-01 kinaba: typedef complex<double> CMP; fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: class FixedNumberOfDigits { public: fef841b401 2020-08-01 kinaba: long long sum(int start, int step, long long numberOfDigits) fef841b401 2020-08-01 kinaba: { fef841b401 2020-08-01 kinaba: return solve(start, step, numberOfDigits); fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: LL solve(LL s, LL inc, LL nd) { fef841b401 2020-08-01 kinaba: LL next = 10; fef841b401 2020-08-01 kinaba: int w = 1; fef841b401 2020-08-01 kinaba: while (next <= s) { fef841b401 2020-08-01 kinaba: next *= 10; fef841b401 2020-08-01 kinaba: w += 1; fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: next = (next - s + inc - 1) / inc * inc + s; fef841b401 2020-08-01 kinaba: LL k = (next - s) / inc; fef841b401 2020-08-01 kinaba: if (k * w >= nd) { fef841b401 2020-08-01 kinaba: LL q = nd / w; fef841b401 2020-08-01 kinaba: LL r = nd % w; fef841b401 2020-08-01 kinaba: if (r == 0) q -= 1, r += w; fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: stringstream ss; fef841b401 2020-08-01 kinaba: ss << (s + inc*q); fef841b401 2020-08-01 kinaba: stringstream ss2; fef841b401 2020-08-01 kinaba: ss2 << ss.str().substr(0, int(r)); fef841b401 2020-08-01 kinaba: LL ans; fef841b401 2020-08-01 kinaba: ss2 >> ans; fef841b401 2020-08-01 kinaba: return ans; fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: return solve(next, inc, nd - k*w); fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: }; fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: // BEGIN CUT HERE fef841b401 2020-08-01 kinaba: #include <ctime> fef841b401 2020-08-01 kinaba: double start_time; string timer() fef841b401 2020-08-01 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } fef841b401 2020-08-01 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) fef841b401 2020-08-01 kinaba: { os << "{ "; fef841b401 2020-08-01 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) fef841b401 2020-08-01 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } fef841b401 2020-08-01 kinaba: void verify_case(const long long& Expected, const long long& Received) { fef841b401 2020-08-01 kinaba: bool ok = (Expected == Received); fef841b401 2020-08-01 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; fef841b401 2020-08-01 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } fef841b401 2020-08-01 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); fef841b401 2020-08-01 kinaba: #define END verify_case(_, FixedNumberOfDigits().sum(start, step, numberOfDigits));} fef841b401 2020-08-01 kinaba: int main(){ fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: CASE(0) fef841b401 2020-08-01 kinaba: int start = 47; fef841b401 2020-08-01 kinaba: int step = 10; fef841b401 2020-08-01 kinaba: long long numberOfDigits = 7LL; fef841b401 2020-08-01 kinaba: long long _ = 7LL; fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(1) fef841b401 2020-08-01 kinaba: int start = 98; fef841b401 2020-08-01 kinaba: int step = 1; fef841b401 2020-08-01 kinaba: long long numberOfDigits = 10LL; fef841b401 2020-08-01 kinaba: long long _ = 101LL; fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(2) fef841b401 2020-08-01 kinaba: int start = 0; fef841b401 2020-08-01 kinaba: int step = 1; fef841b401 2020-08-01 kinaba: long long numberOfDigits = 7LL; fef841b401 2020-08-01 kinaba: long long _ = 6LL; fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(3) fef841b401 2020-08-01 kinaba: int start = 123456789; fef841b401 2020-08-01 kinaba: int step = 10; fef841b401 2020-08-01 kinaba: long long numberOfDigits = 5LL; fef841b401 2020-08-01 kinaba: long long _ = 12345LL; fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(4) fef841b401 2020-08-01 kinaba: int start = 123456789; fef841b401 2020-08-01 kinaba: int step = 10; fef841b401 2020-08-01 kinaba: long long numberOfDigits = 17LL; fef841b401 2020-08-01 kinaba: long long _ = 12345679LL; fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(5) fef841b401 2020-08-01 kinaba: int start = 0; fef841b401 2020-08-01 kinaba: int step = 1; fef841b401 2020-08-01 kinaba: long long numberOfDigits = 15LL; fef841b401 2020-08-01 kinaba: long long _ = 1LL; fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(6) fef841b401 2020-08-01 kinaba: int start = 314; fef841b401 2020-08-01 kinaba: int step = 11; fef841b401 2020-08-01 kinaba: long long numberOfDigits = 9LL; fef841b401 2020-08-01 kinaba: long long _ = 336LL; fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(6) fef841b401 2020-08-01 kinaba: int start = 314; fef841b401 2020-08-01 kinaba: int step = 11; fef841b401 2020-08-01 kinaba: long long numberOfDigits = 192LL; fef841b401 2020-08-01 kinaba: long long _ = 100LL; fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(6) fef841b401 2020-08-01 kinaba: int start = 1; fef841b401 2020-08-01 kinaba: int step = 612; fef841b401 2020-08-01 kinaba: long long numberOfDigits = 10LL; fef841b401 2020-08-01 kinaba: long long _ = 18LL; fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: // END CUT HERE