D. Pythagorean Triples (math、暴力)
题解:
因此c=(a*a-1)/2+1
我们暴力枚举a,从a=1到(a * a-1)/2+1<=n (C需要<=n)
如果满足(a * a-1)%2==0,即b为整数,且c=b+1,C也为整数,符合条件,贡献+1
Code:
#include<iostream>
#include<cmath>
#define pii pair<int,int>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
int main()
{
FAST;
int t;cin >> t;
while (t--)
{
ll n;cin >> n;
int sum = 0;
for (ll i = 1;((i * i) - 1) / 2 + 1 <= n;i++)
{
ll b = i * i - 1;
if (b % 2 == 0 && b >= i) sum++;
}
cout << sum << endl;
}
}