SHARE
TWEET

2017

a guest Jan 24th, 2020 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("2017.in");
  5. ofstream fout("2017.out");
  6. int q, c;
  7. long long k;
  8. long long cautfr(long long n, int c)
  9. {
  10.     long long sol=0, p10=1, ant=0;
  11.     if(n==1 && c==1)
  12.         return 1;
  13.     while(n>=c)
  14.     {
  15.          if(n%10>c)
  16.             sol+=(n/10+1)*p10;
  17.         else if(n%10==c)
  18.             sol+=(n/10)*p10+ant+1;
  19.             else sol += (n/10)*p10;
  20.         ant += (n%10)*p10;
  21.         n /= 10;
  22.         p10*=10;
  23.     }
  24.     return sol;
  25. }
  26. long long cautb(int c, long long k)
  27. {
  28.     long long li=1, ls=1e13, mij, ok;
  29.     while(li<=ls)
  30.     {
  31.         mij=(li+ls)/2;
  32.         if(cautfr(mij,c)>=k)
  33.         {
  34.             ok=mij;
  35.             ls=mij-1;
  36.         }
  37.         else
  38.             li=mij+1;
  39.     }
  40.     return ok;
  41. }
  42. int main()
  43. {
  44.     int i;
  45.     fin>>q;
  46.     for(i=1;i<=q;i++)
  47.     {
  48.         fin>>c>>k;
  49.         fout<<cautb(c,k)<<'\n';
  50.     }
  51.     return 0;
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top