結果

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

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0