较为严格的数学论证如下:对于 y 的每个取值,都有 (y+1)^2-y^2=(y+1+y)(y+1-y)=2y+1 个 x 与其对应,区间为 [y^2,(y+1)^2-1=y^2+2y]。因为 y^2 一定是 y 的倍数,所以 y^2+y, y^2+2y 均为 y 的倍数。故在每个 [y^2,y^2+2y] 中,都会有三个 x 满足题意。 \
因此,设要求的数量为 S ,则可以从以下公式求得:
#include <bits/stdc++.h>
using namespace std;
int q;
long long n;
int main()
{
cin >> q;
while (q--)
{
cin >> n;
long long x = floor(sqrt(n * 1.0L));
long long ans = (x - 1) * 3 + 1;
long long mid = (x * x + (x + 1) * (x + 1) - 1) / 2;
if (n >= mid) ans++;
if (n >= (x + 1) * (x + 1) - 1) ans++;
cout << ans << endl;
}
return 0;
}