結果

問題 No.2125 Inverse Sum
ユーザー HIcoderHIcoder
提出日時 2023-07-12 15:03:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,326 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 102,628 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 05:19:52
合計ジャッジ時間 6,159 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 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 #

#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*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