Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + y bananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.
Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.
Okabe is sure that the answer does not exceed 1018. You can trust him.
Input
The first line of input contains two space-separated integers m and b (1 ≤ m ≤ 1000, 1 ≤ b ≤ 10000).
Output
Print the maximum number of bananas Okabe can get from the trees he cuts.
Example
Input
1 5
Output
30
Input
2 3
Output
25
Note
The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.
#include<stdio.h>
int main()
{
long long int m,b,x;
long long int max,count;
int i,j;
while(scanf("%lld %lld",&m,&b)!=EOF)
{
max=0;
for(i=b;i>=0;i--)//遍历y 此时求得的x一定是一个整数
{
count=0;
x=(b-i)*m;
count=(1+i)*i/2*(x+1)+(1+x)*x/2*(i+1);//求数量用等差数列前n项和
if(count>max)
max=count;
}
printf("%lld\n",max);
}
}
在二维平面上,Okabe需要沿着一条特定的线选择一个轴对齐的矩形区域来收集尽可能多的香蕉。每棵树位于整数坐标上且含有对应数量的香蕉。任务是确定最佳矩形以最大化收获。
2423

被折叠的 条评论
为什么被折叠?



