Time limit: 3.000 seconds
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1935
计算sum{i从右往左数的第一个非0数字,p<=i<=q}。
见代码。。
/*0.016s*/ #include<cstdio> typedef long long ll; ll sum(ll n) { ll ans = 0, x; while (n) { x = n % 10; n /= 10; ans += ((1 + x) * x) / 2 + n * 45;///当个位在循环的时候,高位的朋友你在干嘛? } return ans; } int main() { ll a, b; while (scanf("%lld%lld", &a, &b), a >= 0) printf("%lld\n", sum(b) - sum(a - 1)); }