CF817C Really Big Numbers

思路:

二分。

实现:

 1 #include <iostream>
 2 #include <cstdio>
 3 using namespace std;
 4 
 5 typedef long long ll;
 6 
 7 const ll MAXN = 1e18;
 8 
 9 ll n, s;
10 
11 bool check(ll x)
12 {
13     ll sum = 0;
14     ll tmp = x;
15     while (x)
16     {
17         sum += x % 10;
18         x /= 10;
19     }
20     return tmp - sum >= s; 
21 }
22 
23 int main()
24 {
25     cin >> n >> s;
26     ll l = 0, r = MAXN + 1, res = MAXN + 1;
27     while (l <= r)
28     {
29         ll m = (l + r) >> 1;
30         if (check(m)) r = m - 1, res = m;
31         else l = m + 1;
32     }
33     cout << (n >= res ? n - res + 1 : 0) << endl;
34     return 0;
35 }

 

转载于:https://www.cnblogs.com/wangyiming/p/7078409.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值