結果

問題 No.278 連続する整数の和(2)
ユーザー jjjj
提出日時 2016-08-31 23:13:52
言語 Fortran
(gFortran 13.2.0)
結果
WA  
実行時間 -
コード長 1,008 bytes
コンパイル時間 1,693 ms
コンパイル使用メモリ 32,640 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 22:01:57
合計ジャッジ時間 2,998 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 37 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 49 ms
5,376 KB
testcase_11 AC 29 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 26 ms
5,376 KB
testcase_14 AC 20 ms
5,376 KB
testcase_15 AC 23 ms
5,376 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 36 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  integer*8::C,N,i,j,ABGCD
  read *,N
  if(MOD(N,2).eq.0) then
     ABGCD = gcd(2*N,1+N)
     N = N/2
  else
     ABGCD = gcd(N,(1+N)/2)
  end if
  C = 1

  call sub(ABGCD,C)
  call sub(N,C)

  print '(i0)',C

contains
  subroutine sub(N,c)
    integer*8,intent(inout)::N,C
    integer*8::i,j,SQRTN
    integer*1,allocatable::insuu(:)
    SQRTN  =INT(SQRT(DBLE(N)))

    allocate(insuu(SQRTN))
    insuu = 0
    do i=2,SQRTN
       if(insuu(i).eq.1) continue
       do j=i+i,SQRTN,i
          insuu(j) = 1
       end do

       if(MOD(N,i).eq.0) then
          do
             C = (i+1)*C
             N = N/i
             if(MOD(N,i).ne.0) exit
          end do
       end if

       if(N.eq.1) exit
    end do
    if(N.ne.1) C = C*(1+N)
    deallocate(insuu)

  end subroutine sub

  recursive function gcd(a,b) result(c)
    implicit none
    integer*8::a,b,c
    if(b.eq.0) then
       c = a
    else
       c = gcd(b,MOD(a,b))
    end if
  end function gcd
end program main
0