Helicopter Landing Pad
Time limit2sMemory limit1024 MB
Count subsets S of {1,...,k} for some k such that sum(S) <= a and sum(S^c) <= b, summed over all k, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Prefix sum, Math
- Solved
- No attempts yet
Problem
You want to build a helicopter landing pad on a rooftop so that a helicopter can land there.
The landing pad must satisfy all of the following conditions.
- The landing pad consists of k concentric circles (k ≥ 1).
- The radii of the circles that make up the landing pad are 1, 2, ..., k. That is, they are distinct positive integers from 1 to k.
- The circumference of each circle must be painted with one color of paint.
The size of a landing pad is the radius of the largest concentric circle, which by the conditions above equals the number of circles k.
Two landing pads are different if their sizes differ, or if their sizes are the same but the combinations of colors painted on the concentric circles differ.
Painting the circumference of a circle of radius r requires exactly r cans of paint.
For example, if you have 3 cans of red paint and 4 cans of blue paint, the number of different landing pads you can build with this paint is 9, as shown in the figures below. The X marks indicate the center of the concentric circles.
For reference, among the size-3 landing pads, the one shown below requires 4 = 1 + 3 cans of red paint and 2 cans of blue paint, but the given 3 cans of red paint are not enough, so this landing pad cannot be built.

You currently have a cans of red paint and b cans of blue paint. Write a program that finds the number of different landing pads you can build using only this paint, modulo 10^9 + 7.
A single input contains T test cases to solve.
Input
The first line gives the number of test cases T.
The next T lines give the test cases, one per line. Each line contains two integers a and b separated by a single space.
Output
For each test case, output on its own line the number of different landing pads you can build using only a cans of red paint and b cans of blue paint, modulo 10^9 + 7.
Constraints
- All given numbers are integers.
- 1 ≤ T ≤ 10 000
- 1 ≤ a, b ≤ 50 000


