Weighted Binomial Sum

Company: SNABBIT

Difficulty: medium

Problem Statement

Weighted Binomial Sum For a positive integer N , every subset size i from 1 to N contributes a weight equal to the square of that size, multiplied by the number of subsets of that size drawn from N distinct items. Formally, define S = 1^2 * C(N, 1) + 2^2 * C(N, 2) + 3^2 * C(N, 3) + ... + N^2 * C(N, N) where C(N, i) is the binomial coefficient "N choose i" — the number of ways to choose i items out of N . You are given T independent values of N . For each of them, report S . S is always a whole number, and it grows extremely fast: for the largest allowed N it has more than three hundred decimal digits, so it does not fit in any fixed-width integer type, and every one of those digits must be printed correctly. Your answer must be the exact value — arbitrary-precision arithmetic (or an equivalent digit-by-digit technique) is required. (inferred — the source states the output format as "rounded to 1 decimal place" but never bounds the answer; its own samples print 1.0 , 6.0 , 24.0 , i.e. t