题目链接:哆啦A梦传送门
参考博客:https://blog.csdn.net/haut_ykc/article/details/76404547
题解:
这题先把a分离出来,
令 a*(a+b)=(a+t)*(a+t),得 a=t*t/(b-2*t),其中 a,t为非负整数。
我们观察下这个式子,要想满足a为非负整数,则t的范围为 [0,b/2),而且a是随着t的增大而增大的,故我们要尽量靠近b/2。
如果b为奇数,那么显然 t=(b-1)/2,则a=t*t。
b为偶数,首先t=(b-1)/2,假设此时t为偶数,那么a=t*t/2。要是此时t为奇数,因为a要非负整数,此时t*t不能整除2,所以此时t要减一,即t=(b-4)/2, a=t*t/4。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long LL;
int main()
{
LL a,b,t;
int ncase;
scanf("%d",&ncase);
while(ncase--)
{
scanf("%lld",&b);
if(b&1){
t=(b-1)/2;
printf("%lld\n",t*t);
}
else{
t=(b-2)/2;
if(t&1){
t--;
printf("%lld\n",t*t/4);
}
else{
printf("%lld\n",t*t/2);
}
}
}
return 0;
}