結果

問題 No.2125 Inverse Sum
ユーザー 👑 ygussanyygussany
提出日時 2022-11-18 23:19:31
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,057 bytes
コンパイル時間 3,351 ms
コンパイル使用メモリ 94,432 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 08:20:27
合計ジャッジ時間 7,275 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

long long gcd(long long a, long long b)
{
	if (a == 0) return b;
	else return gcd(b % a, a);
}

typedef struct {
	long long key, id;
} data;

void merge_sort(int n, data x[])
{
	static data y[1001] = {};
	if (n <= 1) return;
	merge_sort(n / 2, &(x[0]));
	merge_sort((n + 1) / 2, &(x[n/2]));
	
	int i, p, q;
	for (i = 0, p = 0, q = n / 2; i < n; i++) {
		if (p >= n / 2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	long long P, Q;
	scanf("%lld %lld", &P, &Q);
	
	long long g = gcd(P, Q);
	P /= g;
	Q /= g;
	
	int i, k = 0;
	long long N, M;
	data d[1001];
	for (N = (Q + P) / P; P * N <= Q * 2; N++) {
		if (N < 1) continue;
		M = Q * N / (N * P - Q);
		if (Q * (N + M) == N * M * P) {
			d[k].key = N;
			d[k++].id = M;
			if (N < M) {
				d[k].key = M;
				d[k++].id = N;
			}
		}
	}
	
	printf("%d\n", k);
	merge_sort(k, d);
	for (i = 0; i < k; i++) printf("%lld %lld\n", d[i].key, d[i].id);
	fflush(stdout);
	return 0;
}
0