結果

問題 No.887 Collatz
ユーザー hyanmahyanma
提出日時 2019-10-05 16:12:33
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 396 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 22,656 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-06 03:16:04
合計ジャッジ時間 1,428 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |   scanf("%d", &n0);
      |   ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include "stdio.h"

int main(){
  int n0;
  int i;
  int max = 1;

  scanf("%d", &n0);

  for(i=1;i > 0;i++){
    if(n0 > max){
      max = n0;
    }
    
    if(n0 == 1){
      printf("%d\n", i);
      break;
    }

    if(n0%2 == 0){
      n0 /= 2;
    }else{
      n0 = 3 * n0 + 1;
    }

    if(n0 == 1){
      printf("%d\n", i);
      break;
    }
  }

  printf("%d\n", max);

  return 0;
}
0