#C6949. Formatted Pascal's Triangle

    ID: 50765 Type: Default 1000ms 256MiB

Formatted Pascal's Triangle

Formatted Pascal's Triangle

Given a non-negative integer \(n\), generate the first \(n\) rows of Pascal's Triangle.

The triangle is constructed as follows:

  • The first row is simply "1".
  • Each subsequent row starts and ends with \(1\).
  • Any inner element in the row is the sum of the two elements directly above it, i.e., if the current row is \(i\) (0-indexed) then the \(j\)th element is \(\binom{i}{j}\), where \(\binom{i}{j} = \binom{i-1}{j-1} + \binom{i-1}{j}\).

Output the triangle with each row on a new line and elements separated by a single space. If \(n < 1\), output an empty string.

inputFormat

Input consists of a single line containing an integer (n) (where (0 \le n \le 100)), representing the number of rows of Pascal's Triangle to generate.

outputFormat

Output Pascal's Triangle with (n) rows. Each row should be printed on a separate line with the elements separated by a single space. If (n) is less than 1, output an empty string.## sample

0