G - Squares
传送门
x * x - y = z * z
(x - z) * (x + z) = y
设 p = x - z
设 q = x + z
得 p * q = y
因为 y = [1 , n]
得 p * q <= n (①)
得 x = (p + q) / 2
得p与 q 必定同奇同偶(②)
根据①可得,q <= y / p ,所以枚举 1 ~ sqrt(n) 即可
根据②可得,区间 [p , q] 中同奇同偶的数一定可以找出一个 x ,所以只要统计有几个同奇同偶的对就可以了
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int mod = 998244353;
typedef long long LL;
int main ()
{
LL n, ans = 0;
cin >> n;
for(LL p = 1; p <= sqrt(n); p ++ )
{
LL q = n / p;
LL cnt = q - p + 1;
ans = (ans + (cnt + 1) / 2 ) % mod;
}
cout << ans << endl;
return 0;
}