結果

問題 No.2426 Select Plus or Minus
ユーザー yansi819
提出日時 2024-04-06 18:22:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 4,359 ms
コンパイル使用メモリ 250,756 KB
最終ジャッジ日時 2025-02-20 22:34:46
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

void solve() {
  ll N; cin >> N;
  int cnt = 0;
  string ans;
  while (N != 1) {
    if (N % 2 == 0) {
      ans += '/';
      N /= 2;
    } else {
      if (N % 4 == 1) {
        ans += '+';
        N = 3 * N + 1;
      } else {
        ans += '-';
        N = 3 * N - 1;
      }
    }
    cnt++;
  }
  cout << cnt << endl;
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
0