poj 3286 How Many 0's?
2016-09-25 10:40
337 查看
Description
A Benedict monk No.16 writes down the decimal representations of all natural numbers between and including m and n, m ≤ n. How many 0’s will he write down?
Input
Input consists of a sequence of lines. Each line contains two unsigned 32-bit integers m and n, m ≤ n. The last line of input has the value of m negative and this line should not be processed.
Output
For each line of input print one line of output with one integer number giving the number of 0’s written down by the monk.
Sample Input
10 11
100 200
0 500
1234567890 2345678901
0 4294967295
-1 -1
Sample Output
1
22
92
987654304
3825876150
Source
Waterloo Local Contest, 2006.5.27
Powered By Saruka
Copyright © 2016 All Rights Reserved.
A Benedict monk No.16 writes down the decimal representations of all natural numbers between and including m and n, m ≤ n. How many 0’s will he write down?
Input
Input consists of a sequence of lines. Each line contains two unsigned 32-bit integers m and n, m ≤ n. The last line of input has the value of m negative and this line should not be processed.
Output
For each line of input print one line of output with one integer number giving the number of 0’s written down by the monk.
Sample Input
10 11
100 200
0 500
1234567890 2345678901
0 4294967295
-1 -1
Sample Output
1
22
92
987654304
3825876150
Source
Waterloo Local Contest, 2006.5.27
/* Problem: 3286 User: saruka Memory: 380K Time: 79MS Language: G++ Result: Accepted */ #include<cstdio> inline int getint() { int r = 0, k = 1; char c = getchar(); for(; c < '0' || c > '9'; c = getchar()) if(c == '-') k = -1; for(; c >= '0' && c <= '9'; c = getchar()) r = r * 10 + c - '0'; return r * k; } long long n, m; long long does(long long num) { if(num < 0) return 0; long long ans = 1, div = 10; while(num / div) { if((num % div - num % (div / 10)) == 0) { ans += ((num / div) - 1) * (div / 10) + (num % (div / 10)) + 1; } else { ans += (num / div) * (div / 10); } div *= 10; } return ans; } int main() { while((scanf("%lld%lld", &m, &n)== 2) && (m != -1) && (n != -1)) { long long result_1 = does(n); long long result_2 = does(m - 1); printf("%lld\n", result_1 - result_2); } return 0; }
Powered By Saruka
Copyright © 2016 All Rights Reserved.
相关文章推荐
- EOJ 1159/POJ 3286 How many 0's?
- POJ - 3286 - How many 0s? 【数位DP】
- POJ 3286 How many 0's? / 2282 The Counting Problem 排列组合统计数字
- POJ 3286 How many 0's?
- poj 3286 How many 0's?
- POJ 3286 How many 0's?(数论)
- POJ 3286 How many 0's?
- poj 3286 How many 0's? --- 数位dp
- poj 3286 How many 0's?
- POJ 3286- How many 0's?(组合数学_区间计数)
- Poj 3286 How many 0's?
- (Relax 数论1.29)POJ 3286 How many 0's?(统计a-b之间-出现的次数)
- TOJ 2294 POJ 3286 How many 0's? 数位dp
- POJ - 3286 - How many 0's? - (统计0的个数)
- POJ 3286 How many 0's?(数位DP)
- poj 2282 The Counting Problem & 3286 How many 0's?
- POJ 3286 How many 0's?(数位DP)
- POJ 3286 How many 0's?
- POJ 3286 How many 0's?
- POJ 2282 The Counting Problem & POJ 3286 How many 0's?(按位计算贡献)