链接)
题意
给定$n$,求有序三元组数量$(a,b,c)$:
- $a + b + c = n$
- $d(a) + d(b) + d(c) = d(n)$
其中$d(114514) = 1+1+4+5+1+4$
题解
假设$a+b+c=n$
- 没有发生任何的进位:那么$d(a)+d(b)+d(c)$显然正确
- 存在一位发生进位:
- 例如5+7(只用两个数说明),原本$d = 5+7 = 12$
- 但是$d(n) = 2$,补上向前进位的数字:$d = 3$
- 所以只要发生进位,$d$一定会减小$9$
所以单独考虑每一位的贡献就可以了
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
| #include <bits/stdc++.h> using namespace std;
long long solve() {
long long n; cin >> n; long long mul = 1; while (n) { long long cnt = 0; for (int i=0;i<=n%10;++i) for (int j=0;j<=n%10;++j) if ( n%10 - i - j >= 0 ) ++cnt; mul *= cnt; n /= 10; } return mul; }
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T; cin >> T; while (T--) { cout << solve() << "\n"; } }
|