2 1 10 1 20
Case #1: 0 Case #2: 1HintThe answer maybe very large, we recommend you to use long long instead of int.
求出区间里面每个数位和模10余0的个数.
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define maxn 22 typedef long long ull; ull a, b; int bit[maxn], l; ull dp[maxn][11]; ull dfs (int pos, int m1, bool f2) { //当前的位数 之前模10余数 是不是可以取到9 if (pos == 0) { return m1 == 0; } if (f2 && dp[pos][m1] != -1) { return dp[pos][m1]; } ull Max = (f2 ? 9 : bit[pos]); ull ans = 0; for (int i = 0; i <= Max; i++) { ans += dfs (pos-1, (m1+i)%10, f2 || (i<Max)); } if (f2) dp[pos][m1] = ans; return ans; } ull f (ull num) { l = 0; while (num) { bit[++l] = num%10; num /= 10; } return dfs (l, 0, 0); } int main () { //freopen ("in.txt", "r", stdin); int t, kase = 0; memset (dp, -1, sizeof dp); cin >> t; while (t--) { cin >> a >> b; printf ("Case #%d: %lld\n", ++kase, f (b)-f (a-1)); } return 0; }