Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- long long z, c;
- cin >> z >> c;
- long long najmal = 1, najgolem;
- for(int i = 0; i < c - 1; i++) {
- najmal *= 10;
- }
- najgolem = najmal * 10 - 1;
- long long L = najmal, R = najgolem;
- long long zbir, broj;
- while(L <= R) {
- long long sredina = (L + R) / 2;
- broj = sredina;
- zbir = 0;
- while(broj > 0) {
- zbir += broj;
- broj /= 10;
- }
- if(zbir == z) {
- cout << sredina << endl;
- return 0;
- }
- if(zbir < z) {
- L = sredina + 1;
- }
- else {
- R = sredina - 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement