思路:只需要保证大数个位是9,大数后面的数字就全部满足条件了,从s循环至n,结束标志便是个位是9的大数;
#include<cstdio>
#include<cstring>
#include<cmath>
#define max_n 10010
using namespace std;
typedef long long LL;
LL f(LL x)
{
LL res=0;
while(x)
{
res+=x%10;
x/=10;
}
return res;
}
int main()
{
LL n,s,ans=0,i;
scanf("%lld %lld",&n,&s);
for(i=s;i<=n;i++)
{
LL k=i-f(i);
if(k>=s)
{
if(i%10==9)
{
break;
}
ans++;
}
}
// printf("%lld %lld\n",ans,i);
if(n>=s)
printf("%lld\n",ans+n-i+1);
else printf("0\n");
return 0;
}