結果
問題 |
No.141 魔法少女コバ
|
ユーザー |
![]() |
提出日時 | 2019-02-22 15:21:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 14 ms / 5,000 ms |
コード長 | 451 bytes |
コンパイル時間 | 393 ms |
コンパイル使用メモリ | 40,704 KB |
最終ジャッジ日時 | 2025-01-06 21:21:28 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 93 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d %d", &N, &M); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <cstdint> #include <algorithm> int gcd(int m, int n) { while (n) std::swap(m %= n, n); return m; } int main() { int N, M; scanf("%d %d", &N, &M); int g = gcd(M, N); M /= g; N /= g; int res = 0; if (N < M) { std::swap(M, N); ++res; } while (N > 1) { if (M < N) { std::swap(M, N); continue; } res += M/N + 1; std::swap(M %= N, N); } printf("%d\n", res+M-1); }