注意到内层等于 1n1 \sim n 的因数个数和,而有且只有平方数有奇数个因数,因此原式等于:

$$\sum_{x=1}^{n} \left( \left\lfloor x \right\rfloor \bmod 2 \right)$$

n\left\lfloor \sqrt{n} \right\rfloor 的奇偶性分类讨论推式子即可。

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int T;
	scanf("%d", &T);
	while (T--)
	{
		long long n;
		scanf("%lld", &n);
		long long c = sqrtl(n + 0.5);
		if (c % 2 == 0) printf("%lld\n", c * (c + 1) / 2);
		if (c % 2 == 1) printf("%lld\n", c * (c - 1) / 2 + n - c * c + 1);
	}
	return 0;
}