結果
問題 | No.2125 Inverse Sum |
ユーザー |
|
提出日時 | 2022-11-18 22:38:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 971 bytes |
コンパイル時間 | 1,555 ms |
コンパイル使用メモリ | 174,920 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-20 03:06:59 |
合計ジャッジ時間 | 2,502 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll P, Q; cin >> P >> Q; auto sqrtll = [&](ll v){ if(v < 0)return -1ll; ll v2 = sqrt(v); for(int i = -5; i <= 5; i++){ if((v2 + i) * (v2 + i) == v)return v2 + i; } return -1ll; }; vector<pair<ll,ll>> ans; for(ll i = 1; i * i <= 1000000 && 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'; } }