結果

問題 No.2426 Select Plus or Minus
ユーザー kuroni
提出日時 2023-08-18 21:18:43
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 459 bytes
コンパイル時間 2,624 ms
コンパイル使用メモリ 243,928 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-28 05:22:25
合計ジャッジ時間 4,198 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int64_t n; cin >> n;
    string s;
    while (n != 1) {
        if (n % 2 == 0) {
            n /= 2;
            s += '/';
        } else if ((3 * n - 1) % 4 == 0) {
            n = 3 * n - 1;
            s += '-';
        } else {
            n = 3 * n + 1;
            s += '+';
        }
    }
    cout << s.size() << '\n' << s;
}
0