結果
問題 | No.2125 Inverse Sum |
ユーザー |
|
提出日時 | 2022-11-18 22:41:18 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,018 bytes |
コンパイル時間 | 1,610 ms |
コンパイル使用メモリ | 174,988 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-20 03:09:33 |
合計ジャッジ時間 | 2,494 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 10 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll P, Q, g; cin >> P >> Q; g = __gcd(P, Q); P /= g, Q /= g; auto sqrtll = [&](ll v){ if(v < 0)return -1ll; ll v2 = sqrt(v); for(int i = -15; i <= 15; i++){ if((v2 + i) * (v2 + i) == v)return v2 + i; } return -1ll; }; vector<pair<ll,ll>> ans; for(ll i = 1; i * i <= 10000000 && i * i * P * P <= 1000000000000000000ll; i++){ ll d = sqrtll(i * i * P * P - 4 * Q * i ); if(d == -1)continue; if((i * P + d) & 1)continue; ans.emplace_back((i * P - d) >> 1, (i * P + d) >> 1); ans.emplace_back((i * P + d) >> 1, (i * P - d) >> 1); } sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); cout << ans.size() << '\n'; for(int i = 0; i < ans.size(); i++){ cout << ans[i].first << ' ' << ans[i].second << '\n'; } }