Skip to content

Commit

Permalink
fix p20
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Oct 12, 2024
1 parent f9b4623 commit 7addbda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions fortran/src/include/constants.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

9 changes: 5 additions & 4 deletions fortran/src/p0020.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7addbda

Please sign in to comment.