Getting WA at this problem: https://www.codechef.com/problems/MATHCHEF

Any hints or test cases?
Here’s my solution: https://www.codechef.com/viewsolution/37559841