素数の総和は4バイト整数からオーバーフローしてしまいました。
ソース・プログラム
program PEuler010 implicit none print *, sum( int(ieratos(2 * 10**6), kind = 8) ) ! int4 overflow stop contains function ieratos(n) ! thieve of Eratostenes integer, intent(in) :: n integer, allocatable :: ieratos(:) logical :: tab(n) integer :: i tab = .true. tab(1) = .false. do i = 2, int( sqrt(real(n)) ) if ( tab(i) ) tab(i * i:n:i) = .false. end do ieratos = pack( [ (i, i = 1, n) ], mask = tab ) return end function ieratos end program PEuler010
実行結果
142913828922
続行するには何かキーを押してください . . .