結果

問題 No.2534 コラッツ数列
コンテスト
ユーザー osada-yum
提出日時 2023-11-10 22:19:28
言語 Fortran
(gFortran 15.2.0)
コンパイル:
gfortran _filename_ -O2 -o ./a.out
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,037 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 435 ms
コンパイル使用メモリ 37,376 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-13 04:31:31
合計ジャッジ時間 1,781 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

program yukicoder_2534
  use, intrinsic :: iso_fortran_env
  implicit none
  integer(int32), parameter :: max_iter = 50
  integer(int32) :: n
  integer(int32) :: i
  read(input_unit, *) n
  call operation_1(n)
contains
  subroutine operation_1(n)
    integer(int32), intent(in) :: n
    call operation_2(n, 2)
  end subroutine operation_1
  recursive subroutine operation_2(n, i)
    integer(int32), intent(in) :: n, i
    if (i > max_iter) then
       write(output_unit, '(a)') "No"
       stop
    else if (n == 1) then
       write(output_unit, '(a)') "Yes"
       write(output_unit, '(i0)') i
       stop
    end if
    call operation_3(n, i + 1)
  end subroutine operation_2
  recursive subroutine operation_3(n, i)
    integer(int32), intent(in) :: n, i
    if (i > max_iter) then
       write(output_unit, '(a)') "No"
       stop
    end if
    if (iand(n, b'1') == 0) then
       call operation_2(n / 2, i + 1)
    else
       call operation_2(3 * n + 1, i + 1)
    end if
  end subroutine operation_3
end program yukicoder_2534
0