Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef long long ll;
- ll presmetuvanje_zbir(ll n)
- {
- ll zbir=0,pom=n;
- while(pom>0)
- {
- zbir+=pom;
- pom/=10;
- }
- return zbir;
- }
- int main()
- {
- ll z;
- int c;
- cin>>z>>c;
- ll l=pow(10,c-1),r=pow(10,c)-1;
- ll res=0;
- while(l<=r)
- {
- ll middle=(l+r)/2;
- ll zbir=presmetuvanje_zbir(middle);
- if(zbir==z)
- {
- res=middle;
- break;
- }
- else if(zbir<z)
- l=middle+1;
- else
- r=middle-1;
- }
- cout<<res;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment