結果

問題 No.2426 Select Plus or Minus
ユーザー bortik
提出日時 2023-08-18 23:23:46
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 466 bytes
コンパイル時間 1,670 ms
コンパイル使用メモリ 192,968 KB
最終ジャッジ日時 2025-02-16 10:49:36
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

int main(){
    long long n; cin >> n;
    int ans = 0;
    string s;
    while(n != 1){
        if(n % 2 == 0){
            s += "/";
            n /= 2;
        } else {
            n *= 3;
            if(n % 4 == 1){
                n -= 1;
                s += "-";
            } else {
                n += 1;
                s += "+";
            }

        }
        ans++;
    }
    cout << ans << endl << s;
}
0