这种傻逼题也能放 G??
Question
给定 ,求出所有使得 为整数的 。
Solution
不妨设 ,那么可以推得:
那么直接枚举每个 的因数算出来 check 一下就行了,时间复杂度 。
Code
粘了一个 int128 的开根,不过好像不需要 int128。
/**
* author: luuia
* created: 2025.08.24 20:32:16
**/
#include<bits/stdc++.h>
using ll = long long;
using ld = long double;
using i128 = __int128;
#define For(i,j,k) for(int i = j;i <= k;i++)
#define Rep(i,j,k) for(int i = j;i >= k;i--)
#define pb push_back
using namespace std;
const int N = 1e6 + 10,p = 998244353;
bool sqrtt(i128 x){if(x < 0) return 0;ld dx = x;
i128 r = floor(sqrt(dx) + 0.5L),rr = (i128)r * r;
if(rr == x) return 1;if(((i128)(r + 1) * (r + 1)) == x) return 1;
if(r > 0 && ((i128)(r - 1) * (r - 1)) == x) return 1;return 0;
}void sol(){ll x;cin >> x;ll m = x * 4 - 1,n = llabs(m);vector<ll> o;
set<ll> s;for(ll i = 1;i * i <= n;i++){if(n % i) continue;
for(auto f : {1,-1}){ll a = f * i,b = m / a;if(m % a) continue;
if(a & 1 == 0 || b & 1 == 0 || a + b & 3 || b - a - 2 & 3) continue;
i128 t = (b - a - 2) / 4,v = t * t + t + x;
if(sqrtt(v) && !s.count(t)) s.insert(t),o.pb(t);
}
}sort(o.begin(),o.end());cout << o.size() << '\n';
for(auto x : o) cout << x << " ";cout << '\n';
}int main(){
// freopen("input.in","r",stdin);
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
ll T = 1;while(T--) sol();return 0;
}