diff --git a/fortran/src/include/constants.f90 b/fortran/src/include/constants.f90 index 513018cb..4944952c 100644 --- a/fortran/src/include/constants.f90 +++ b/fortran/src/include/constants.f90 @@ -25,6 +25,7 @@ module constants ! misc integer, parameter :: MAX_FACTORIAL_64 = 20 + integer(i18t), parameter :: ten16 = 10000000000000000_i18t integer(i18t), parameter :: ten17 = 100000000000000000_i18t end module constants diff --git a/fortran/src/p0020.f90 b/fortran/src/p0020.f90 index 8ffb2f82..cef543a3 100644 --- a/fortran/src/p0020.f90 +++ b/fortran/src/p0020.f90 @@ -20,15 +20,16 @@ pure integer(i18t) function p0020() result(answer) power = 1 answer = 0 - numbers = (/ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 /) + numbers = 0 + numbers(1) = 1 do i = 2, 100 do j = 1, size(numbers) numbers(j) = numbers(j) * i end do do j = 1, size(numbers) - 1 - if (numbers(j) > ten17) then - numbers(j + 1) = numbers(j + 1) + numbers(j) / ten17 - numbers(j) = mod(numbers(j), ten17) + if (numbers(j) > ten16) then + numbers(j + 1) = numbers(j + 1) + numbers(j) / ten16 + numbers(j) = mod(numbers(j), ten16) end if end do end do