CodeForces
来源:互联网 发布:怎么弄个java服务器 编辑:程序博客网 时间:2024/06/11 14:53
Ivan likes to learn different things about numbers, but he is especially interested inreally big numbers. Ivan thinks that a positive integer numberx is really big if the difference betweenx and the sum of its digits (in decimal representation) is not less thans. 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 ofreally big numbers that are not greater thann.
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.
The first (and the only) line contains two integers n ands (1 ≤ n, s ≤ 1018).
Print one integer — the quantity of really big numbers that are not greater thann.
12 1
3
25 20
0
10 9
1
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 than25 (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).
题目大意:
在从0 - n中,有多少个数是可以他的本身减去每位数字然后比s大的。
Hint:
可以先从s找,找第一个符合条件的数,然后用n减去就可以
AC代码
#include<bits/stdc++.h>using namespace std;long long s,n;bool check(long long x){ long long sum = 0; long long temp = x; while(x > 0){ sum += x % 10; x /= 10; } if(temp - sum >= s){ return true; } return false;}int main(){ cin >> n >> s; for(long long i = s; i <= n; i++){ if(check(i)){ cout << n - i + 1 << endl; return 0 ; } } cout << 0 << endl; return 0;}
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Opencv实战(一) 视频人数统计(C++ & Opencv)前后背景分离方法
- Hbase 简单操作Java示例
- python sklearn包——cross validation笔记
- jdbc环境配置以及进行简单的增 删 改
- HDU 4893 Wow! Such Sequence!
- CodeForces
- 先验,后验和似然
- Springmvc @ResponseBody与@RequestBody忽略空值字段
- 宝塔 Linux/Windows 面板
- 为什么淹死的都是会水的?
- 关于Java多线程---------(3,同步与死锁)
- Machine Learning Course 1 and 2
- 软件架构理论体系v4.0的畅想
- 后台服务的系统错误和逻辑错误不同