Send your feedback or ask for help here!
My solution looks fine in theory, but timeouts in the big number test (rest is fine). Then I created another solution with memoization of results but this one goes out of memory in the the big number test.
It looks I miss some idea from number theory that would allow cutting computation needs dramatically.
Okay problem solved. Thanks @Kecsapo