In the vibrant land of Numeria, where numbers are not just symbols but the essence of life itself, the annual Festival of Sums is a spectacle of mathematical prowess. This year, the festival introduces a new challenge, captivating the minds of Numerians: to craft summations that not only meet but can also exceed a specified sum $$$S$$$, using the orderly sequence of multiples of a chosen number $$$P$$$. This challenge embodies Numeria's celebration of abundance and precision, inviting participants to demonstrate their skill in navigating the realms of numbers beyond the exactness, into the realm of surplus.
As a contender in this celebrated festival, you are presented with an array of numbers from $$$1$$$ to $$$N$$$. Your quest involves solving $$$Q$$$ puzzles, for each puzzle you must find how many unique ways you can select two distinct positive integers $$$i$$$, and $$$j$$$ such that $$$j - i \leq 10^3$$$, and sum all numbers $$$kP$$$ where $$$i \leq k \leq j$$$ and $$$kP \leq N$$$ for a given prime number $$$P$$$ such that the total sum is at least $$$S$$$. Two selections are different if any of the values for $$$i$$$ and $$$j$$$ differ.
The first line of input contains an integer $$$N$$$ ($$$1 \leq N \leq 10^9$$$), indicating the array of numbers in the festival contains the values $$$1$$$ to $$$N$$$.
The following line introduces $$$Q$$$ ($$$1 \leq Q \leq 10^4$$$), the number of puzzles to solve in the celebration.
Each of the next $$$Q$$$ lines contains two integers $$$S$$$ and $$$P$$$ ($$$1 \leq S \leq 10^9$$$, $$$1 \leq P \leq N$$$), with $$$S$$$ being the target sum and $$$P$$$ the specified multiple.
Output $$$Q$$$ lines, where the $$$i$$$-th line contains the answer to the $$$i$$$-th puzzle of the input.
20310 210 315 5
44 14 6
2031 21 31 5
45 15 6
| Название |
|---|


