結果

問題 No.2534 コラッツ数列
ユーザー osada-yumosada-yum
提出日時 2023-11-10 22:19:28
言語 Fortran
(gFortran 14.2.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,037 bytes
コンパイル時間 521 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-26 01:45:17
合計ジャッジ時間 1,474 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

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