題解:
這道題我看的是別人的解釋,
https://www.cnblogs.com/shingen/p/7105280.html
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL long long
int main()
{
LL m,b;
while(~scanf("%lld%lld",&m,&b))
{
LL sum=0,ans=0;
for(int y=0;y<=b;y++)
{
LL x=(b-y)*m;
LL sum= x*(1+x)/2*(1+y)+y*(1+y)/2*(1+x);
//等差數列求和公式推導
ans=max(sum,ans);
}
printf("%lld\n",ans);
}
}