HDU 2032 Yang Hui triangle
Yang Hui triangle
Problem Description Do you still remember the Yang Hui triangle I learned in middle school? The specific definition is not described here. You can refer to the following figure:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
The Input data contains multiple test instances. The Input of each test instance only contains a positive integer n (1 <=n <= 30), indicating the number of layers in the Yang Hui triangle to be output.
Output corresponds to each input. Please Output the Yang Hui triangle of the corresponding layers. Integers of each layer are separated by a space. An empty line is added after each Yang Hui triangle.
Sample Input
2 3
Sample Output
11 111 11 2 1
# Include
Long YH (int n, int m) {long I = 1, j = 1, s1 = 1, s2 = 1; if (m = 1) return 1; else {m --; n --; for (j = 1; j <= m; j ++) {s1 = s1 * (n --); s2 * = j; if (s1% s2 = 0) // reduce s1 and s2 as early as possible, otherwise {s1/= s2; s2 = 1 ;}} return s1/s2;} int main (void) {long int n; while (scanf (% d, & n )! = EOF) {int I, j; for (I = 1; I <= n; I ++) {for (j = 1; j <= I; j ++) {if (j = 1) printf (% ld, YH (I, j); elseprintf (% ld, YH (I, j);} printf ();} printf ();} return 0 ;}