#QHD0000092. Tháp đỏ xanh (Red-Green Towers)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tháp đỏ xanh (Red-Green Towers)
Red-Green Towers
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You have red blocks and green blocks. A tower of height has exactly blocks on its bottom level, blocks on the next, and so on, down to a top level with one block. Every level is monochromatic: all its blocks must be red or all must be green.
A tower of height uses exactly
blocks. Some blocks may remain unused. Let be the maximum possible height using the available blocks.
Count how many different towers of height exactly can be built. Two towers differ if at least one level has a different color, even when the total number of red or green blocks is equal. Output the count modulo .
For , the only level may be red or green, yielding two towers. For , the maximum height is four because , and two different colorings are possible.
Input
A single line contains integers , the available red and green block counts.
Output
Print the number of maximum-height towers modulo .
Subtasks
-
Subtask 1 (20 points): , .
-
Subtask 2 (30 points): , .
-
Subtask 3 (50 points): , .
Examples
Example 1
Input
4 6
Output
2
Explanation: The ten available blocks give . To use exactly four red blocks, color the level of size four red, or color the levels of sizes one and three red. Hence there are two towers.
Example 2
Input
1 1
Output
2
Explanation: The maximum height is one. Its single level may be either red or green, yielding two towers.
Example 3
Input
0 3
Output
1
Explanation: A height-two tower is possible with three green blocks, and only one coloring exists because there are no red blocks.