Educational Codeforces Round 23.C

C. Really Big Numbers
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. 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 of really big numbers that are not greater than n.

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 and s (1 ≤ n, s ≤ 1018).

Output

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

Examples
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 than 25 (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).

思路:对于一个数n增加1时各位数之和最多加1,因此找到第一个满足条件的数之后均满足。

代码:

 #include<stdio.h>
 #include<iostream>
 #include<algorithm>
 #include<string.h>
 #include<math.h>
 #include<stdlib.h>
 #include<ctype.h>
 #include<stack>
 #include<queue>
 #include<map>
 #include<set>
 #include<vector>
 #define ll long long
 #define  db double
 using namespace std;
 ;
 ;
 ll f(ll x)
 {
     ll res=;
     while(x)
     {
         res+=x%;
         x/=;
     }
     return res;
 }
 int main()
 {
     ll n,s,i;
     scanf("%lld %lld",&n,&s);
     for(i=s;i<=n;i++)
     {
         ll k=i-f(i);
         if(k>=s)
         {
             break;
         }
     }
     printf(:);
     ;
 }
上一篇:jquery选择指定元素之外的所有元素


下一篇:Oracle 11g OEM登录后提示“出现内部错误”