NC25051. [USACO 2007 Feb L]Digit Sums
描述
输入描述
Line 1: Three space-separated integers, respectively: A, B, and D
输出描述
Line 1: A single integer representing the number of integers in between A and B that have a digit sum of D.
示例1
输入:
1 20 2
输出:
3
说明:
How many numbers between 1 and 20 have a digit sum of 2?Python3 解法, 执行用时: 43ms, 内存消耗: 7604K, 提交时间: 2023-08-18 11:32:29
a, b, d = map(int, input().split()) ans = 0 if d == 9: if a % 9 == 0: ans += 1 if b % 9 == 0: ans += 1 else: if a % 9 == d: ans += 1 if b % 9 == d: ans += 1 ans += (b-a) // 9 print(0 if d == 0 else ans)