結果

問題 No.1936 Rational Approximation
ユーザー 👑 ygussanyygussany
提出日時 2022-05-13 22:22:53
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 535 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 28,956 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-29 07:49:01
合計ジャッジ時間 3,695 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
6,076 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

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

int main()
{
	int P, Q, p[2], q[2], g;
	long long tmp;
	scanf("%d %d", &P, &Q);
	for (p[0] = P / 2; p[0] >= 1; p[0]--) {
		tmp = (long long)p[0] * Q;
		if (tmp % P == 1) {
			q[0] = (tmp - 1) / P;
			break;
		} else if (tmp % P == P - 1) {
			q[0] = (tmp + 1) / P;
			break;
		}
	}
	p[1] = P - p[0];
	q[1] = Q - q[0];
	g = gcd(p[1], q[1]);
	p[1] /= g;
	q[1] /= g;
	printf("%d\n", p[0] + q[0] + p[1] + q[1]);
	fflush(stdout);
	return 0;
}
0