Good Triples (Codeforces 1907E)
Tags: Others, number theory

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.

Input: 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$$$).

Output: For each test case output one integer, the number of good triples for the given integer $$$n$$$. Order of integers in a triple matters.

Note: 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)$$$.

Sample Inputs:
12
11
0
1
2
3
4
5
3141
999
2718
9999999
10000000

Sample Outputs:
9
1
3
6
10
15
21
1350
166375
29160
1522435234375
3

Solution (Python):
import bisect
import math
import sys
from collections import Counter
from math import inf
input = lambda : sys.stdin.readline().rstrip()

def II():
    return int(input())

def SI():
    return sys.stdin.readline().rstrip()

def LII():
    return list(map(int, input().split()))

def TI():
    return map(int, input().split())
Y = 'YES'
N = 'NO'
if __name__ == '__main__':
    t = II()
    for i in range(t):
        n = II()
        m = n
        mp = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55]
        a = 1
        while n > 0:
            a *= mp[n % 10]
            n //= 10
        print(a)

Solution (Python):
from sys import stdin
from math import comb
input = stdin.readline

def dig_sum(x):
    return sum([int(ch) for ch in str(x)])
for case in range(int(input())):
    n = int(input())
    found = []
    ans = 1
    for dig in str(n):
        dig = int(dig)
        ans *= comb(dig + 2, 2)
    print(ans)

Solution (Python):
d = {}
for i in range(10):
    d[i] = (i + 1) * (i + 2) // 2
o = []
for i in range(int(input())):
    l = list(map(int, list(input())))
    p = 1
    for i in l:
        p *= d[i]
    o.append(p)
print(*o, sep='\n')