1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| #include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1e9 + 7; int cnt[20]; void muti(int c[][2], int a[][2], int b[][2]) { int tmp[2][2] = {0}; for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) for (int k = 0; k < 2; ++k) tmp[i][j] = (tmp[i][j] + a[i][k] * b[k][j]) % mod; memcpy(c, tmp, sizeof tmp); } void qmi(int c[][2], int i, int k) { int res[][2] = {{1, 0}, {0, 1}}; int t[][2] = { {10, 0}, {i, 1}}; while (k) { if (k & 1) muti(res, res, t); muti(t, t, t); k >>= 1; } memcpy(c, res, sizeof res); } void solve() { int m; cin >> m; for (int i = 0; i < 10; ++i) cin >> cnt[i]; int st = 0; if (m == 1 && cnt[0]) { cout << 0 << '\n'; return; } for (int i = 1; i < 10; ++i) { if (cnt[i]) { st = i, cnt[i]--, m--; break; } } int o[][2] = { {st, 1}, {0, 0}}; for (int i = 0; i < 10; ++i) { if (!m) break; if (cnt[i]) { int bit[][2] = { {1, 0}, {0, 1}}; int num = min(cnt[i], m); qmi(bit, i, num); muti(o, o, bit); m -= num; } } cout << o[0][0] << '\n'; } signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int _; cin >> _; while (_--) solve(); }
|