天天看點

uva 847 a multiplication game  Polynomial coefficients 

 Polynomial coefficients 

The Problem

The problem is to calculate the coefficients in expansion of polynomial (x1+x2+...+xk)n.

The Input

The input will consist of a set of pairs of lines. The first line of the pair consists of two integers n and k separated with space (0<K,N<13). This integers define the power of the polynomial and the amount of the variables. The second line in each pair consists of k non-negative integers n1, ..., nk, where n1+...+nk=n.

The Output

For each input pair of lines the output line should consist one integer, the coefficient by the monomial x1n1x2n2...xknk in expansion of the polynomial (x1+x2+...+xk)n.

Sample Input

2 2
1 1
2 12
1 0 0 0 0 0 0 0 0 0 1 0
      

Sample Output

2
2      
#include <cstdio>

int main () {
    long long n;
    while (scanf ("%lld", &n) == 1) {
        int cnt = 0;
        while (n > 1) {
            if (cnt % 2 == 1) {
                n = n / 2 + n % 2;
            } else {
                if (n % 9 == 0) {
                    n = n / 9;
                } else {
                    n = n / 9 + 1;
                }
            }
            ++cnt;
        }
        printf ("%s wins.\n", cnt % 2 == 1 ? "Stan" : "Ollie");
    }
    return 0;
}
           

繼續閱讀