Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- long long z;
- long long c;
- cin>>z>>c;
- long long k=1;
- long long k1=c-1;
- for(int k2=0; k2<k1; k2++){
- k*=10;
- }
- long long s=k;
- long long e=k*10-1;
- while(s<=e){
- long long middle=(e+s)/2;
- long long middle1=middle;
- long long z1=0;
- while (middle1>0){
- z1+=middle1;
- middle1/=10;
- }
- if(z1==z){
- cout<<middle;
- return 0;
- }
- if(z1<z){
- s=middle+1;
- }
- if(z1>z){
- e=middle-1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement