結果
問題 | No.2125 Inverse Sum |
ユーザー |
|
提出日時 | 2022-11-18 23:21:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,069 bytes |
コンパイル時間 | 2,087 ms |
コンパイル使用メモリ | 202,248 KB |
最終ジャッジ日時 | 2025-02-08 22:29:29 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; void calc_ft(const vector<pair<ll, int>>& x, int id, ll y, vector<ll>& ret) { if (id == x.size()) { ret.push_back(y); return; } auto [f, c] = x[id]; ll pk = 1; for (int i = 0; i <= c; i ++) { calc_ft(x, id + 1, y * pk, ret); pk *= f; } } int main () { ll P, Q; cin >> P >> Q; ll Q2 = Q * Q; vector<pair<ll, int>> fts; for (ll x = 2; x * x <= Q; x ++) { if (Q % x) { continue; } int c = 0; while (Q2 % x == 0) { Q2 /= x; c ++; } fts.emplace_back(x, c); } vector<ll> R; calc_ft(fts, 0, 1, R); vector<pair<ll, ll>> ans; Q2 = Q * Q; for (auto d : R) { ll d2 = Q2 / d; if (((d + Q) % P) ||((d2 + Q) % P)) { continue; } ans.emplace_back((d + Q) / P, (d2 + Q) / P); } cout << ans.size() << endl; for (auto [n, m] : ans) { cout << n << " " << m << endl; } }