5463: 红绿塔

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:4 通过:4

题目描述


There are r red and g green blocks for construction of the red-green tower. Red-green tower can be built following next rules:
  • Red-green tower is consisting of some number of levels;
  • Let the red-green tower consist of n levels, then the first level of this tower should consist of n blocks, second level − of n-1 blocks, the third one − of n-2 blocks, and so on − the last level of such tower should consist of the one block. In other words, each successive level should contain one block less than the previous one;
  • Each level of the red-green tower should contain blocks of the same color.
Let h be the maximum possible number of levels of red-green tower, that can be built out of r red and g green blocks meeting the rules above. The task is to determine how many different red-green towers having h levels can be built out of the available blocks.
Two red-green towers are considered different if there exists some level, that consists of red blocks in the one tower and consists of green blocks in the other tower.
You are to write a program that will find the number of different red-green towers of height h modulo109+7.

你有r块红色的积木和g块绿色的积木,它们用于建造红绿塔。红绿塔按照下面的规则来建造:

  • 红绿塔有若干层;
  • 如果红绿塔有n层,那么塔的第一层应该有n块积木,第二层有n-1块,第三层有n-2块,以此类推,最后一层只有一块。换言之,每一层应该比前面一层少一块;
  • 红绿塔的每一层必须使用相同颜色的积木。

设h是红绿塔的目标层数,它由r块红色积木和g快绿色积木组成,并且满足上述规则。现在你的任务是确定可以建造出多少不同的有h层的红绿塔。

如果两个红绿塔相同的一层使用的是不同的颜色,它们就被认为不同的。

你需要写一个程序来求出有多少种高度为h的不同的红绿塔。由于答案很大,你只需要输出答案模10^9+7(也就是1000000007)后的值。

Examples
Input
4 6
Output
2
Input
9 7
Output
6
Input
1 1
Output
2
Note
The image in the problem statement shows all possible red-green towers for the first sample.

输入格式

输入仅有一行,用空格隔开的两个数r和g,表示可用的红色、绿色积木的数量

输出格式

输出仅一行,高度为h的不同红绿塔的个数模10^9+7的值

输入样例 复制


输出样例 复制


分类标签