Good Triples
题面翻译
题目描述
给定一个整数 $n$,我们称三元组 $(a,b,c)$ 是“好的”,当且仅当 $a+b+c=n$ 并且 $digsum(a)+digsum(b)+digsum(c)=digsum(n)$。这里的 $digsum(x)$ 指的是 $x$ 各个数位之和。
并且三元组的顺序也很重要。例如 $(4,12,10)$ 和 $(10,12,4)$ 不是相同的三元组。
求不同三元组的数量。
题目描述
Given a non-negative integer number $ n $ ( $ n \ge 0 $ ). Let’s say a triple of non-negative integers $ (a, b, c) $ is good if $ a + b + c = n $ , and $ digsum(a) + digsum(b) + digsum(c) = digsum(n) $ , where $ digsum(x) $ is the sum of digits of number $ x $ .
For example, if $ n = 26 $ , then the pair $ (4, 12, 10) $ is good, because $ 4 + 12 + 10 = 26 $ , and $ (4) + (1 + 2) + (1 + 0) = (2 + 6) $ .
Your task is to find the number of good triples for the given number $ n $ . The order of the numbers in a triple matters. For example, the triples $ (4, 12, 10) $ and $ (10, 12, 4) $ are two different triples.
输入格式
The first line of input contains a single integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases. Descriptions of test cases follow.
The first and only line of the test case contains one integer $ n $ ( $ 0 \le n \le 10^7 $ ).
输出格式
For each test case output one integer, the number of good triples for the given integer $ n $ . Order of integers in a triple matters.
样例 #1
样例输入 #1
12
11
0
1
2
3
4
5
3141
999
2718
9999999
10000000
样例输出 #1
9
1
3
6
10
15
21
1350
166375
29160
1522435234375
3
提示
In the first example, the good triples are $ (0, 0, 11) $ , $ (0, 1, 10) $ , $ (0, 10, 1) $ , $ (0, 11, 0) $ , $ (1, 0, 10) $ , $ (1, 10, 0) $ , $ (10, 0, 1) $ , $ (10, 1, 0) $ , $ (11, 0, 0) $ .
In the second example, there is only one good triple $ (0, 0, 0) $ .
因为是3元组,可以算一下0~9每一个数可以有多少种三元方案,每一个数位的三元方案全部乘起来就是总方案数
const int N = 4e5 + 10;
int a[N];
void solve()
{
int n;
cin >> n;
int ans = 1;
while (n)
{
ans *= a[n % 10];
n /= 10;
}
cout << ans << '\n';
}
signed main()
{
buff;
int t = 1;
cin >> t;
for (int i = 0; i <= 9; i++)
for (int j = 0; j <= 9; j++)
for (int k = 0; k <= 9; k++)
if (i + j + k <= 9) a[i + j + k]++;
while (t--) solve();
return 0;
}