Advertisement
Josif_tepe

Untitled

May 26th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     long long z;
  8.     long long c;
  9.  
  10.     cin>>z>>c;
  11.     long long k=1;
  12.     long long k1=c-1;
  13.  
  14.     for(int k2=0; k2<k1; k2++){
  15.     k*=10;
  16.     }
  17.  
  18.     long long s=k;
  19.     long long e=k*10-1;
  20.  
  21.     while(s<=e){
  22.     long long middle=(e+s)/2;
  23.     long long middle1=middle;
  24.     long long z1=0;
  25.     while (middle1>0){
  26.     z1+=middle1;
  27.     middle1/=10;
  28.     }
  29.     if(z1==z){
  30.     cout<<middle;
  31.     return 0;
  32.     }
  33.     if(z1<z){
  34.         s=middle+1;
  35.     }
  36.     if(z1>z){
  37.         e=middle-1;
  38.     }
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement