CodeForces

来源:互联网 发布:怎么弄个java服务器 编辑:程序博客网 时间:2024/06/11 14:53

Ivan likes to learn different things about numbers, but he is especially interested inreally big numbers. Ivan thinks that a positive integer numberx is really big if the difference betweenx and the sum of its digits (in decimal representation) is not less thans. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity ofreally big numbers that are not greater thann.

Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.

Input

The first (and the only) line contains two integers n ands (1 ≤ n, s ≤ 1018).

Output

Print one integer — the quantity of really big numbers that are not greater thann.

Example
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
Note

In the first example numbers 10, 11 and 12 are really big.

In the second example there are no really big numbers that are not greater than25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).

In the third example 10 is the only really big number (10 - 1 ≥ 9).


题目大意:

在从0 - n中,有多少个数是可以他的本身减去每位数字然后比s大的。

Hint:

可以先从s找,找第一个符合条件的数,然后用n减去就可以


AC代码

#include<bits/stdc++.h>using namespace std;long long s,n;bool check(long long x){    long long sum = 0;    long long temp = x;    while(x > 0){        sum += x % 10;        x /= 10;    }    if(temp - sum >= s){        return true;    }    return false;}int main(){    cin >> n >> s;    for(long long i = s; i <= n; i++){        if(check(i)){            cout << n - i + 1 << endl;            return 0 ;        }    }    cout << 0 << endl;    return 0;}

原创粉丝点击