結果

問題 No.2125 Inverse Sum
ユーザー HIcoder
提出日時 2023-07-12 15:01:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,330 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 100,668 KB
最終ジャッジ日時 2025-02-15 10:04:58
ジャッジサーバーID
(参考情報)
judge2 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 TLE * 1 -- * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;

const ll MOD=998244353;
const double PI=acos(-1);

int main(){
    ll p,q;
    cin>>p>>q;

    ll lb=(q+(p-1))/p;
    ll ub=2*q/p;

    vector<pair<ll,ll>> cand;
    
    for(ll m=lb;m<=ub;m++){
        if(m*p==q) continue;

        //if(m*(m*p-q)>q) break;

        //if(q>=m*(m*p-q)){

            if(m*q%(m*p-q)==0){
                ll n=m*q/(m*p-q);
                if(n<m) break;
                cand.emplace_back(m,n);

            }
        // }else{
        //     break;
        // }
    }
    
    /*
    for(ll n=1;n*n<=q;n++){
        if(q%n==0){
            {
                
                ll m=q/n;

                if(n+m==p){
                    //mn=q, m+n=p
                    cand.emplace_back(n,m);
                }
            }

        


        }
    }
    */

    vector<pair<ll,ll>> ans;
    for(auto [m,n]:cand){
            ans.emplace_back(m,n);
        if(m!=n){
            ans.emplace_back(n,m);
        }
    }

    cout<<ans.size()<<endl;
     for(auto [m,n]:ans){
        cout<<m<<' '<<n<<endl;
     }

    
}
0