The question is a bit vague, but if I’m understanding correctly: try this testcase:
1
1 12 35831808 84
(NB: 12 ** 7 == 35831808)
Your solution appears to give “no” for this, but (again, if I understand it correctly!) the answer should be “yes” - this should hopefully allow you to debug your approach
Edit:
Oh, and welcome
Edit2:
Although my non-brute-force solution is getting WA, so maybe you should just ignore all this XD
Edit3:
What a Comedy of Errors that was XD! AC now. Note to self: 1) stop making absurdly stupid assumptions(!!); 2) stop arbitrarily disallowing certain values in your testcase generator(!)