Problem 2961 · Medium
Reduce each power modulo 10 first, then raise it modulo m, and keep the indexes that hit the target.
Open the interactive visualisation