結果

問題 No.2125 Inverse Sum
ユーザー icchi224
提出日時 2022-11-18 23:02:39
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 996 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 201,196 KB
最終ジャッジ日時 2025-02-08 22:19:57
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) std::begin(x), std::end(x)
using namespace std;
using ll = long long;
void opvec1(vector<int> &vec);
void opvec2(vector<vector<int>> &vec);
void opset(set<int> &S);

int main() {
  ll P, Q;
  cin >> P >> Q;
  set<pair<ll, ll>> S;
  for (ll n = 1; n < 100000; n++) {
    ll a = Q * n;
    ll b = P * n - Q;
    if (b > 0 && !(a % b)) {
      ll m = a / b;
      S.insert(make_pair(n, m));
      S.insert(make_pair(m, n));
    }
  }
  cout << S.size() << endl;
  for (auto s: S) {
    cout << s.first << " " << s.second << endl;
    assert(P*s.first*s.second == Q*(s.first+s.second));
  }
}

//
void opvec1(vector<int> &vec) {
  rep(i, vec.size()) cout << vec[i] << " ";
  cout << endl;
}
void opvec2(vector<vector<int>> &vec) {
  rep(i, vec.size()) {
    rep(j, vec[0].size()) cout << vec[i][j] << " ";
  cout << endl;
  }
}
void opset(set<int> &S) {
  for (auto s: S) cout << s << " ";
  cout << endl;
}
0