Very hard math/ad hoc problem AI can't solve

I’ve spent a lot of time on this problem, there’s no editorial, I can’t find a solution online, and even AI can’t solve it. (Free tier)

Here’s the link to the problem: https://dmoj.ca/problem/ccc26s5