The statement has directly shown the way to solve (by formulas) the problem, but it is not very easy to do since the result could be a very large number. It is hardly to use big-number calculating to fit the given time-limit. The problem needs only the result by modulo of 1,000,000,007 but we can not compare the numbers by their remainders.
Fortunately we have an effective way to solve it by combining some mathematical theories as follows:
At first, we can store the value of P_i by storing its logarithm instead;
Then instead of doing a lot of multiplications (which causes very large results), we just do a series of additions between their logarithms (which are quite small real numbers);
At last, we do tracing and calculate the needed result by modulo of 1,000,000,007; this work does not need big-number processing since we can take the remainders after every multiplication.