Vipul and modulus

What is the expected memory limit for this problem?
here is my solution, Even editorial sol. didn’t pass the limit

https://pastebin.com/2WnD7kuC