結果
問題 |
No.442 和と積
|
ユーザー |
|
提出日時 | 2018-06-06 17:39:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 663 bytes |
コンパイル時間 | 116 ms |
コンパイル使用メモリ | 23,424 KB |
実行使用メモリ | 8,224 KB |
最終ジャッジ日時 | 2024-06-30 10:17:28 |
合計ジャッジ時間 | 2,917 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 4 WA * 1 RE * 2 TLE * 1 -- * 10 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:4:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 4 | scanf("%lld %lld", &A, &B); | ~~~~~^~~~~~~~~~~~~~~~~~~~~ main.cpp:3:29: warning: ‘X’ may be used uninitialized in this function [-Wmaybe-uninitialized] 3 | long long int A, B, X, Y, Z, W, V, ANS; | ^
ソースコード
#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; }