L. Lost Land of Numeralia
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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

Output $$$Q$$$ lines, where the $$$i$$$-th line contains the answer to the $$$i$$$-th puzzle of the input.

Examples
Input
20
3
10 2
10 3
15 5
Output
44
14
6
Input
20
3
1 2
1 3
1 5
Output
45
15
6