結果

問題 No.442 和と積
ユーザー kashi3215kashi3215
提出日時 2018-06-06 17:39:09
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 663 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 25,800 KB
実行使用メモリ 8,764 KB
最終ジャッジ日時 2023-09-12 22:46:40
合計ジャッジ時間 3,128 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,764 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 RE -
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 RE -
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:3:22: warning: ‘X’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  long long int A, B, X, Y, Z, W, V, ANS;
                      ^

ソースコード

diff #

#include<cstdio>
int main(void) {
	long long int A, B, X, Y, Z, W, V, ANS;
	scanf("%lld %lld", &A, &B);

	if (A == 1 || B == 1) { printf("1"); }
	else
	X = A + B;
	Y = A;
	while (X%Y != 0 && Y % X != 0) {
		if (X > Y) { X = X % Y; }
		else { Y = Y % X; }
	}
	if (X > Y) { ANS = Y; }
	else { ANS = X; }
	Z = A + B;
	W = B;
	while (Z%W != 0 && W % Z != 0) {
		if (Z > W) { Z =Z % W; }
		else { W = W % Z; }
	}
	if (Z > W) { ANS = ANS * W; }
	else { ANS = ANS * Z; }

	V = A + B;

	while (V%ANS != 0 && ANS % V != 0) {
		if (V > ANS) { V = V % ANS; }
		else { ANS = ANS % V; }
	}
	
	if (ANS > V) { printf("%lld", V); }
	else {
		printf("%lld", ANS);
	}
	return 0;

}
0