結果

問題 No.16 累乗の加算
ユーザー jjjj
提出日時 2016-09-12 22:07:56
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 548 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 26,960 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 12:01:34
合計ジャッジ時間 845 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  integer*8::x,N,total,i
  integer*8,allocatable::a(:)
  integer,parameter::modulo=1000003
  data total/0/
  read *,x,N
  allocate(a(N))
  read *,a
  do i=1,N
     total = total + power(x,a(i))
  end do
  print '(i0)',MOD(total,modulo)
contains
  recursive function power(x,p) result(y)
    integer*8::x,y,p
    integer,parameter::modulo=1000003
    if(p.eq.0) then
       y = 1
       return
    end if
    y = power(mod(x*x,modulo),p/2)
    if(MOD(p,2).eq.1) y = mod(y*x,modulo)
  end function power
end program main
0