CodeForces

来源:互联网 发布:mac上安装apt get 编辑:程序博客网 时间:2024/06/01 10:31

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 1011 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 3030 - 3 ≥ 20).

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


题目意思是给你一个n,n减去他的每一位数字之和是否大于给出的s,在小于等于n的所有数字中,有多少个符合这种情况的数

先用二分选定一个范围,比如第一个样例的12,中间数是6,6不满足这个条件,继续二分到9,9也不满足这个条件,继续二分到10,10-(1+0)>=1,满足了,那么大于10小于n的数都必定是满足的。


#include<iostream>using namespace std;typedef long long ll;int main(){ll n,s;cin>>n>>s;ll l=0,r=n;while(l<=r){ll mid=(l+r)/2;ll temp=mid;ll sum=0;while(temp){sum+=temp%10;temp/=10;}if(mid-sum<s) l=mid+1;else r=mid-1;}cout<<n-r<<endl;}