We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Magic Number Tree
You are viewing a single comment's thread. Return to all 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.