結果

問題 No.16 累乗の加算
ユーザー mi_
提出日時 2016-05-07 14:25:22
言語 Fortran
(gFortran 14.2.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,552 bytes
コンパイル時間 1,318 ms
コンパイル使用メモリ 20,608 KB
最終ジャッジ日時 2024-11-15 04:44:18
合計ジャッジ時間 1,718 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
Main.f90:39:13:

   39 |     if (iand(b, 1) .eq. 1) then  ! bが奇数の場合、
      |             1
Error: Arguments of 'iand' have different kind type parameters at (1)
Main.f90:48:7:

   48 |   use module_modular
      |       1
Fatal Error: Cannot open module file 'module_modular.mod' for reading at (1): No such file or directory
compilation terminated.

ソースコード

diff #
プレゼンテーションモードにする

!>
!! @brief (modular arthmeric)
!!
!! @note . n
!! xnx{0, 1, ..., n-1}.
!! .
!!
!! @date 2016/05/07
!!
module module_modular
implicit none
public :: modpow
contains
!>
!! @brief 2(repeated squaring)(modular exponetiation)
!!
!! @note Fortrana, b
!! 2
!!
recursive function modpow(a, b, n) result(d)
implicit none
integer(8), intent(in) :: a, b, n
integer(8) :: d
if (b .eq. 0) then !
d = 1
return
end if
d = modpow(mod(a * a, n), b / 2, n)
! bd^b = ((d^2)^(b/2))n/2
if (iand(b, 1) .eq. 1) then ! b
d = mod((d * a), n) ! d^b = ((d^2)^(b/2)) * an/2
end if
end function modpow
end module module_modular
program main
use module_modular
implicit none
integer(8) :: output, b, x, n, i
integer(8), parameter :: m = 1000003
character(9500) input, output2
character(100) output1
character(10), parameter :: delim = " "
read(*,*) x, n
read(*, '(a)') input
output = 0
do i = 1, n
call split(input, output1, output2, delim)
input = output2
read(output1, *) b
output = output + modpow(x, b, m)
output = mod(output, m)
end do
write(*, '(I0)') output
contains
subroutine split(input, output1, output2, delim)
implicit none
character(*), intent(inout) :: input
character(*), intent(out) :: output1
character(*), intent(out) :: output2
character(*), intent(in) :: delim
integer :: index
input = trim(input)
index = scan(input, delim)
output1 = input(1:index-1)
output2 = input(index+1:)
end subroutine split
end program main
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0