Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // VGTU ACM ICPC selection C
- #include <iostream>
- using namespace std;
- long long int ggg;
- long long int n, x;
- long long int pages(long long int nd, long long int first)
- {
- long long int tenpow = 1;
- int ndig = 0;
- long long int t = first;
- while(t > 0)
- {
- t = t/10; // 10
- tenpow *= 10;
- ndig += 1;
- }
- long long int sum = 0;
- long long int last = first - 1 + nd / ndig; // ndig
- while(last >= tenpow)
- {
- sum += tenpow - first;
- nd -= (tenpow - first) * ndig;
- first = tenpow;
- tenpow *= 10;
- ndig += 1;
- last = first - 1 + nd / ndig; // ndig
- }
- if(nd % ndig > 0)
- {
- return -1;
- }
- return sum + (last - first + 1);
- }
- int main()
- {
- cin >> ggg;
- for(long long int i=0;i<ggg;i++)
- {
- cin >> n >> x;
- cout << pages(n, x) << endl; // n - nd, x - first
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement