結果

問題 No.2125 Inverse Sum
ユーザー harurunharurun
提出日時 2022-11-18 22:00:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,945 bytes
コンパイル時間 5,020 ms
コンパイル使用メモリ 222,492 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 06:50:34
合計ジャッジ時間 9,427 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <string>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <stack>
#include <random>
#include <complex>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <assert.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll=long long;
#define read(x) cin>>(x);
#define readll(x) ll (x);cin>>(x);
#define readS(x) string (x);cin>>(x);
#define readvll(x,N) vector<ll> (x)((N));for(int i=0;i<(N);i++){cin>>(x)[i];}
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define rep2d(i,j,H,W) for(ll (i)=0;(i)<(H);(i)++)for(ll (j)=0;(j)<(W);j++)
#define is_in(x,y) (0<=(x) && (x)<H && 0<=(y) && (y)<W)
#define yn {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define double_out(x) fixed << setprecision(x)
template<class T> inline void erase_duplicate(vector<T>& A){sort(A.begin(),A.end());A.erase(unique(A.begin(),A.end()),A.end());}
inline ll powll(ll x,ll n){ll r=1;while(n>0){if(n&1){r*=x;};x*=x;n>>=1;};return r;}

long long gcd(long long x,long long y){
  long long tmp;
  while(y!=0){
    tmp=y;
    y=x%y;
    x=tmp;
  }
  return x;
}

int main(){
  ll P,Q;
  cin>>P>>Q;
  if(P==Q){
    cout<<"1\n2 2"<<endl;
    return 0;
  }
  ll G=gcd(P,Q);
  P/=G;
  Q/=G;
  const ll mmm=10000;
  vector<pair<ll,ll>> ans;
  for(ll k=1;k<mmm;k++){
    ll q=k*Q;
    ll p=k*P;
    for(ll N=1;N*N<=q;N++){
      if(q%N==0 && q/N+N==p){
        ll M=q/N;
        ans.push_back(make_pair(N,M));
        ans.push_back(make_pair(M,N));
      }
    }
  }
  erase_duplicate(ans);
  cout<<ans.size()<<endl;
  for(const pair<ll,ll>& i:ans){
    cout<<i.first<<" "<<i.second<<endl;
  }
}

0