#include<iostream> #include<cstdio> usingnamespace std; constint maxm = 2e6 + 5; constint mod = 1e9 + 7; int f[10][maxm]; voidinit() { for (int i = 0; i < 10; i++) f[i][0] = 1; for (int j = 1; j < maxm; j++) { for (int i = 0; i < 10; i++) if (i + j < 10) f[i][j] = 1; else f[i][j] = (f[0][i + j - 10] + f[1][i + j - 10]) % mod; } } intmain() { init(); int kase; scanf("%d",&kase); while (kase--) { int n, m; scanf("%d%d",&n,&m); int res = 0; while (n) { int i = n % 10; n /= 10; res = (res + f[i][m]) % mod; } cout << res << "\n"; } return0; }
intdfs(int pos, int last, bool limit) { int &ans = dp[pos][last][limit];
if (pos == cnt) return ans = 1; if (ans != -1) return ans;
ans = 0; for (int v = 0; v <= (limit ? A[pos] : 9); v++) { if (last == 6 && v == 2 || v == 4) continue; ans += dfs(pos + 1, v, limit && v == A[pos]); } return ans; }
#include<iostream> #include<vector> #include<cstring> #include<algorithm> usingnamespace std; int A[8], cnt, dp[8][12][2];
intdfs(int pos, int last, bool limit) { int &ans = dp[pos][last][limit];
if (pos == cnt) return ans = 1; if (ans != -1) return ans;
ans = 0; for (int v = 0; v <= (limit ? A[pos] : 9); v++) { if (last == 6 && v == 2 || v == 4) continue; ans += dfs(pos + 1, v, limit && v == A[pos]); } return ans; }
intf(int x) { cnt = 0; memset(dp, -1, sizeof(dp)); memset(A, 0, sizeof(A)); while (x) A[cnt++] = x % 10, x /= 10; reverse(A, A + cnt); returndfs(0, 11, true); } intmain() { int x, y; while (cin >> x >> y && (x || y)) { cout << f(y) - f(x - 1) << endl; } return0; }
#include<iostream> #include<algorithm> #include<cstring> #define int long long usingnamespace std; constint maxn = 65; int cnt = 0; int L[maxn], R[maxn]; int dp[maxn][2][2][2][2];
intdfs(int p, bool l1, bool r1, bool l2, bool r2) { if (p == cnt) return0; int &ans = dp[p][l1][r1][l2][r2]; if (ans != -1) return ans; ans = 0; for (int i = (l1 ? L[p] : 0); i <= (r1 ? R[p] : 1); i++) for (int j = (l2 ? L[p] : 0); j <= (r2 ? R[p] : 1); j++) { ans = max(ans, ((i ^ j) << (cnt - p-1)) + dfs(p + 1, l1 && i == L[p], r1 && i == R[p], l2 && j == L[p], r2 && j == R[p])); } return ans; }
int x, y; cin >> x >> y; while (x) L[cnt1++] = x & 1, x >>= 1; while (y) R[cnt2++] = y & 1, y >>= 1; cnt = max(cnt1, cnt2); reverse(L, L + cnt); reverse(R, R + cnt);
#include<iostream> #include<vector> #include<algorithm> #include<cstring> usingnamespace std; #define int long long constint maxn = 31; constint mod = 1e9 + 7; int cnt; int dp[maxn][maxn][2][2]; int X[maxn], Y[maxn];
intdfs(int pos, int max_bit, int limit1, int limit2) { if (max_bit == 0) return0; if (pos == cnt) return max_bit; int &ret = dp[pos][max_bit][limit1][limit2]; if (ret != -1) return ret; ret = 0; int ex = (limit1 ? X[pos] : 1); int ey = (limit2 ? Y[pos] : 1); for (int i = 0; i <= ex; i++) { for (int j = 0; j <= ey; j++) { if (i + j == 0 && max_bit == cnt-pos) { ret += dfs(pos + 1, max_bit - 1, limit1 && (i == X[pos]), limit2 && (j == Y[pos])); ret %= mod; } elseif ((i & j) == 0) { ret += dfs(pos + 1, max_bit, limit1 && (i == X[pos]), limit2 && (j == Y[pos])); ret %= mod; } } } return ret; } intf(int x, int y) { cnt = 0; int x_cnt = 0, y_cnt = 0; memset(dp, -1, sizeof(dp)); memset(X, 0, sizeof(X)); memset(Y, 0, sizeof(Y)); while (x) X[x_cnt++] = x & 1, x >>= 1; while (y) Y[y_cnt++] = y & 1, y >>= 1; cnt = max(x_cnt, y_cnt); reverse(X, X + cnt); reverse(Y, Y + cnt); returndfs(0, cnt, 1, 1); } signedmain() { int T;
scanf("%d", &T); while (T--) { int x, y; scanf("%d%d", &x, &y); printf("%d\n", f(x, y)); } return0; }
#include<iostream> #include<vector> #include<algorithm> #include<cstring> usingnamespace std; #define int long long constint maxn = 31; constint mod = 1e9 + 7; int cnt; int dp[maxn][maxn][2][2]; int X[maxn], Y[maxn]; int ans = 0; intdfs(int pos, int limit1, int limit2, bool zero) { if (pos == cnt) return1; int &ret = dp[pos][limit1][limit2][zero]; if (ret != -1) return ret; ret = 0; int ex = (limit1 ? X[pos] : 1); int ey = (limit2 ? Y[pos] : 1); int tot = 0; for (int i = 0; i <= ex; i++) { for (int j = 0; j <= ey; j++) { if (i & j) continue; if (zero && (i | j)) { int tmp = dfs(pos + 1, limit1 && (i == ex), limit2 && (j == ey), false); tot = (tot + tmp) % mod; ret = (ret + tmp) % mod; } else { ret += dfs(pos + 1, limit1 && (i == ex), limit2 && (j == ey), zero && (i + j == 0)); ret %= mod; } } } ans = (ans+ (tot * (cnt - pos))) % mod; return ret; } intf(int x, int y) { cnt = 0; ans = 0; int x_cnt = 0, y_cnt = 0;
memset(dp, -1, sizeof(dp)); memset(X, 0, sizeof(X)); memset(Y, 0, sizeof(Y)); while (x) X[x_cnt++] = x & 1, x >>= 1; while (y) Y[y_cnt++] = y & 1, y >>= 1; cnt = max(x_cnt, y_cnt); reverse(X, X + cnt); reverse(Y, Y + cnt); dfs(0, cnt, 1, 1); return ans; } signedmain() { int T;
scanf("%lld", &T); while (T--) { int x, y; scanf("%lld%lld", &x, &y); printf("%lld\n",f(x,y)); } return0; }