結果

問題 No.2125 Inverse Sum
ユーザー HIcoderHIcoder
提出日時 2023-07-12 18:11:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 1,486 bytes
コンパイル時間 1,092 ms
コンパイル使用メモリ 109,404 KB
実行使用メモリ 6,312 KB
最終ジャッジ日時 2023-10-12 08:27:34
合計ジャッジ時間 3,099 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,356 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,356 KB
testcase_08 AC 2 ms
4,356 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 1 ms
4,356 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 141 ms
6,312 KB
testcase_28 AC 129 ms
5,676 KB
testcase_29 AC 41 ms
4,640 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 129 ms
5,732 KB
testcase_32 AC 45 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

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);

ll gcd(ll x,ll y){
    return y==0?x:gcd(y,x%y);
}



int main(){
    ll P,Q;
    cin>>P>>Q;

    ll g=gcd(P,Q);
    P/=g;
    Q/=g;

    vector<ll> div;

    for(ll i=1;i*i<=Q;i++){
        if(Q%i==0){
            div.push_back(i);

            if(Q/i!=i){
                div.push_back(Q/i);
            }
        }
    }


    set<pair<ll,ll>> cand;

    for(ll d1: div){
        for(ll d2:div){
            //d1=N', d2=M'に該当

            if((Q/d2)%d1==0 && (d1+d2)%P==0){

                ll mul=Q/(d1*d2);

                mul*=(d1+d2)/P;

                //ans[0].push_back(mul*d1);
                //ans[1].push_back(mul*d2);
                cand.emplace(mul*d1,mul*d2);


            }
        }
    }


    if(cand.size()==0){
        cout<<0<<endl;
        return 0;
    }

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

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