結果

問題 No.2125 Inverse Sum
ユーザー SSRSSSRS
提出日時 2022-11-18 21:32:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,253 bytes
コンパイル時間 1,814 ms
コンパイル使用メモリ 182,176 KB
実行使用メモリ 5,204 KB
最終ジャッジ日時 2023-10-20 06:19:25
合計ジャッジ時間 3,202 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 72 ms
5,204 KB
testcase_28 AC 57 ms
5,164 KB
testcase_29 AC 35 ms
4,392 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 57 ms
5,164 KB
testcase_32 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int P, Q;
  cin >> P >> Q;
  int Q2 = Q;
  long long X = (long long) Q * Q;
  vector<pair<long long, int>> F1;
  for (int i = 2; i * i <= Q2; i++){
    if (Q2 % i == 0){
      int cnt = 0;
      while (Q2 % i == 0){
        cnt++;
        Q2 /= i;
      }
      F1.push_back(make_pair(i, cnt * 2));
    }
  }
  if (Q2 > 1){
    F1.push_back(make_pair(Q2, 2));
  }
  int cnt = F1.size();
  vector<long long> F = {1};
  for (int i = 0; i < cnt; i++){
    int sz = F.size();
    vector<long long> F2;
    for (int j = 0; j < sz; j++){
      long long x = F[j];
      for (int k = 0; k <= F1[i].second; k++){
        F2.push_back(x);
        if (k < F1[i].second){
          x *= F1[i].first;
        }
      }
    }
    F = F2;
  }
  sort(F.begin(), F.end());
  int cnt2 = F.size();
  vector<pair<long long, long long>> ans;
  for (int i = 0; i < cnt2; i++){
    long long x = F[i],  y = X / F[i];
    if ((x + Q) % P == 0 && (y + Q) % P == 0){
      long long N = (x + Q) / P;
      long long M = (y + Q) / P;
      ans.push_back(make_pair(N, M));
    }
  }
  int T = ans.size();
  cout << T << endl;
  for (int i = 0; i < T; i++){
    cout << ans[i].first << ' ' << ans[i].second << endl;
  }
}
0