結果

問題 No.2125 Inverse Sum
ユーザー 👑 potato167potato167
提出日時 2022-11-17 19:47:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 888 bytes
コンパイル時間 4,171 ms
コンパイル使用メモリ 210,080 KB
実行使用メモリ 4,416 KB
最終ジャッジ日時 2023-10-20 05:48:53
合計ジャッジ時間 3,834 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
N=an
M=am
1/N + 1/M = (n+m)/anm 
P/Q=(n+m)/anm
a=(n+m)Q/nmP
*/

//Nの正の約数を列挙する
vector<long long> Divisors(long long N){
    vector<long long> p,q;
    long long i=1,K=0;
    while(i*i<N){
        if(N%i==0){
            p.push_back(i);
            q.push_back(N/i);
            K++;
        }
        i++;
    }
    if(i*i==N) p.push_back(i);
    for(int i=K-1;i>=0;i--){
        p.push_back(q[i]);
    }
    return p;
}
int main() {
	ll P,Q;
	cin>>P>>Q;
	auto div=Divisors(Q);
	vector<pair<ll,ll>> ans;
	for(auto n:div) for(auto m:div){
		if(Q%(n*m)!=0) continue;
		if(__gcd(n,m)!=1) continue;
		ll X=(n+m)*Q;
		ll Y=n*m*P;
		if(X%Y!=0) continue;
		ll a=X/Y;
		ans.push_back({a*n,a*m});
	}
	sort(ans.begin(),ans.end());
	cout<<ans.size()<<"\n";
	for(auto x:ans) cout<<x.first<<" "<<x.second<<"\n";
}
0