Project Euler #205: Dice Game

  • + 0 comments

    There is a way to beat all test cases. Initially I used pure combinatorics but this proved to be too slow. One can notice that frequencies of given scores are the coefficients of followinng polynomial P(x) = x + x^2 + ... x^d raised to power n P(x)^n where n is the number of dice. Calculating it directly is way to inefficient, but we can use FFT, specifically its special variant NTT(Number Theoretic Transform). As a n-th root of unity we can use g^k where g in our case is primitive root modulo 1012924417 and k = 483. So we can use direct FFT to get Y vector, then raise every element of the vector to the proper power and then use inverse FFT to get the vector P(x)^n.