結果

問題 No.2125 Inverse Sum
ユーザー umezoumezo
提出日時 2022-11-18 23:03:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,294 bytes
コンパイル時間 2,323 ms
コンパイル使用メモリ 215,140 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 08:02:06
合計ジャッジ時間 3,423 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 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 WA -
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
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 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 WA -
testcase_23 AC 2 ms
4,348 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
4,348 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

vector<ll> divisor(ll x){
  set<ll> s;
  for(ll i=1;i*i<=x;i++){
    if(x%i==0){
      s.insert(i);
      s.insert(x/i);
    }
  }
  vector<ll> res;
  for(auto y:s) res.push_back(y);
  return res;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll p,q;
  cin>>p>>q;
  
  if(p==2*q){
    cout<<1<<endl;
    cout<<1<<" "<<1<<endl;
    return 0;
  }
  if(p==q){
    cout<<1<<endl;
    cout<<2<<" "<<2<<endl;
    return 0;
  }
  if(3*q==2*p){
    cout<<2<<endl;
    cout<<1<<" "<<2<<endl;
    cout<<2<<" "<<1<<endl;
    return 0;
  }
  if(p==q+1){
    cout<<2<<endl;
    cout<<1<<" "<<q<<endl;
    cout<<q<<" "<<1<<endl;
    return 0;
  }
  if(p>q){ 
    cout<<0<<endl;
    return 0;
  }
  
  ll g=gcd(p,q);
  p/=g,q/=g;
  
  vector<ll> A=divisor(q);
  sort(ALL(A));
  
  vector<ll> N,M;
  int a=A.size();
  rep(i,a){
    if(p-A[i]<=0) continue;
    auto t=lower_bound(ALL(A),p-A[i])-A.begin();
    if(t==a) continue;
    if(A[t]+A[i]==p){
      N.push_back(q/A[i]);
      M.push_back(q/A[t]);
    }
  }
  int n=N.size();
  cout<<n<<endl;
  for(int i=n-1;i>=0;i--){
    cout<<N[i]<<" "<<M[i]<<endl;
  }
    
  return 0;
}
0