Try to solve the following problem, only by combining meaning but not the generating function.
There are q times inquiries, Given k, P, a, each time, print the value of this sum, $$$q,k,P,a \leq 1e5$$$.
I'll give an answer in 24 hours. If solved, please write the method in the comments and try the harder problems below, which replace 2 by t, t will be given before all queries.