I think the complexity be bounded by M \cdot log(Q) similar to concept of harmonic series but I’m not sure.
Edit- I realized there can be multiple values with the same denominator after reading the editorial.
I think the complexity be bounded by M \cdot log(Q) similar to concept of harmonic series but I’m not sure.
Edit- I realized there can be multiple values with the same denominator after reading the editorial.