CF817C Really Big Numbers

Posted 王宜鸣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }

 

以上是关于CF817C Really Big Numbers的主要内容,如果未能解决你的问题,请参考以下文章

Really Big Numbers CodeForces - 817C (数学规律+二分)

codeforces 817C Really Big Numbers

UVa10220:I Love Big Numbers !

CF1447B Numbers Box

CF1447B Numbers Box

CF1447B Numbers Box