#C3305. Digit Sum Pascal's Triangle
Digit Sum Pascal's Triangle
Digit Sum Pascal's Triangle
In this problem, you are given a single integer ( m ) and you are required to generate and print the first ( m ) rows of Pascal's Triangle. However, there is a twist: each element in the triangle should be replaced by the sum of its digits.
For example, the classic Pascal's Triangle row [1, 4, 6, 4, 1] will be transformed into [1, 4, 6, 4, 1] since the digit sums of 1, 4, 6, 4 and 1 are 1, 4, 6, 4 and 1 respectively. In more interesting cases, if the sum of the digits exceeds one digit, only the sum is printed. The approach requires you to generate the triangle in the usual way and then transform each element ( n ) into ( \text{digit_sum}(n) ), where:
[
\text{digit_sum}(n)=\sum_{i} d_i
]
with (d_i) being the digits of ( n ).
inputFormat
The input consists of a single integer ( m ) (( 1 \le m \le 100 )) on a single line, representing the number of rows of the triangle to be generated.
outputFormat
Print exactly ( m ) lines. The ( i^{th} ) line (starting at ( i=1 )) should contain the digit-sum version of the ( i^{th} ) row of Pascal's Triangle. The numbers in each row should be separated by a single space.## sample
1
1
</p>