Comments

The key idea here is keeping invariants, this is precisely what's happening in the code. In the case of finding the smallest $$$x$$$ satisfying $$$f(x)$$$ we initially choose $$$l$$$ and $$$r$$$ such that $$$f(l)$$$ does not hold and $$$f(r)$$$ holds. Throughout the whole binary search, we always keep $$$l$$$ and $$$r$$$ that way. In the case of maximizing $$$x$$$, we keep the invariant that $$$f(l)$$$ holds and $$$f(r)$$$ does not hold (or in the code, $$$g(l)$$$ and $$$g(r)$$$).

The answer is not 0, but 0 mod P, which means that the actual integer answer is a multiple of P = 998244353.

What was the idea behind the different input and output in E1 and E2? You could fix k = 2 and m = 3 and still write them into the input, and I find it unfortunate that my solution with modulo didn't work in E1, but did in E2. The last sentence of the problem statement, "You must output the exact value of the answer.", is in my opinion contradicting to "you DON'T NEED to output the answer by modulo.", especially when the word "NEED" is written in caps.

Usually, you can just submit the hard version also for the easy problem.

Edit: I enjoyed the contest besides that, thanks for it!

Your solution is not O(q) per test case, since you calculate the gcd: https://en.wikipedia.org/wiki/Euclidean_algorithm#Algorithmic_efficiency So it's around O(q + log(a))

Yeah you are right, editorials still expose too much information

I don't see what you mean, contests are much different from practicing. This editorial is different to editorial to programming contests because the solution to the problems is just one plain answer, it doesn't depend on some custom input, of which you have too many to handle them all by themselves. But one problem I see with using the editorials instead of a judge on these math questions is that you can't get a WA without finding out the correct answer of the problem, that's unfortunate

The answers for the problems are all in the tutorial, there is no need to submit them.