Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <vector>
- using namespace std;
- typedef long long ll;
- int main() {
- ll Z, C;
- cin >> Z >> C;
- ll L = 1, R = 1;
- for(int i = 0; i < C; i++) {
- L *= 10;
- R *= 10;
- }
- L /= 10;
- R -= 1;
- while(L <= R) {
- ll middle = (L + R) / 2;
- ll number = middle;
- ll sum = number;
- while(number > 0) {
- number /= 10;
- sum += number;
- }
- if(sum == Z) {
- cout << middle << endl;
- return 0;
- }
- if(sum < Z) {
- L = middle + 1;
- }
- else {
- R = middle - 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement