Magic Number Tree

  • + 0 comments

    I have a naive solution which finds all possible game paths, sums there magic numbers and divides by number of paths only passes two submission tests.

    I understand why it timeouts and maybe gets errors due to recursion depth, but why result could be incorrect?

    I use following code for result: res = (total_summ * math.factorial(n) // path_count) % (10**9+9)

    Python has arbitrary length integers, so this should work. I use integer division, first multiplying and then dividing, because problem states that Em * n! will always be integer.