Comments
+1

You're going to be doing that for every testcase though. So it'll require at least $$$2e9$$$ operations when $$$t = 2000$$$. You can use map/hashmap to keep count of the primes factors.

Ignore below, it does work.

Though even then, I'm not convinced you won't TLE in later testcases.

Ignoring TLE, your solution is wrong. For the test case $$$[7, 13]$$$, it outputs "YES" when it should be "NO".

Let $$$dp[i]$$$ denote the minimum number of deletions for the suffix starting on the $$$i$$$-th element: $$$a[i..n]$$$. Base case will be $$$dp[n + 1] = 0$$$.

For $$$dp[i]$$$, we can either delete or take it. If we delete it then $$$dp[i] = dp[i + 1] + 1$$$. If we take it, then the problem reduces to the suffix starting on the $$$j = (i + a[i] + 1)$$$-th element: $$$a[j..n]$$$. So $$$dp[i] = dp[i + a[i] + 1]$$$. We take the minimum.

Suppose we start with $$$x = 1$$$, $$$y = 1$$$, $$$m = 0$$$. What are the possible $$$(x, y)$$$ reachable using the 4 operations given and the minimum number of operations to achieve that state? We use BFS for that purpose.

We get the optimal solution if we use the tool when the timer is at 1. If we increase the timer past $$$a$$$, it will be set to $$$a$$$. We have two outcomes:

$$$(x + 1 \leq a):$$$ timer change, $$$1 \to x + 1 \to a$$$ increase of $$$a- 1$$$

$$$(x + 1 \lt a):$$$ timer change, $$$1 \to x + 1$$$ increase of $$$x$$$

Think there's a mistake in 1874C — Jellyfish and EVA tutorial. The transition should be:

$$$ \forall 1 \lt i \leq k , g_{k, i} = g_{k-2, i-2} \times \frac{\mathbf{i - 2}}{k} + g_{k-2,i-1} \times \frac{k-i}{k} $$$