#B AC 31 min 1 wrong try by WHD

#A AC 50 min by WDP

#D AC 75 min 3 wrong tries by WHD

#G AC 79 min 5 wrong tries

It can be solved by brute force, but I used DP to solve it, so I wasted a lot of time.

#C AC 94 min 1 wrong try

For a query, if b>sqrt(n), we can response it by brute force.

After do some preparations in O(n^1.5), we can response qeuries whose b<=sqrt(n) in O(1).

#F AC 118 min 1 wrong try by WHD

#E AC 179 min by WDP