Skip to content

Commit

Permalink
Solve p15 in fortran (3)
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Oct 9, 2024
1 parent 8c636a3 commit 41ce61c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fortran/src/include/math.f90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pure integer(i18t) function factorial(n) result(answer)
end do
end function

pure integer(i18t) function n_choose_r(n, r) result(answer)
integer(i18t) function n_choose_r(n, r) result(answer)
integer, intent(in) :: n, r
if (n <= MAX_FACTORIAL_64) then
answer = factorial(n) / factorial(r) / factorial(n-r) ! fast path if small enough
Expand Down Expand Up @@ -45,9 +45,9 @@ integer(i18t) function n_choose_r_slow(n, r) result(answer)
do i = n, 2, -1 ! this loop reduces to prime factors only
do j = 2, i - 1
if (mod(i, j) == 0) then
factors(j) += factors(i)
factors(i / j) += factors(i)
factors(i) = 0;
factors(j) = factors(j) + factors(i)
factors(i / j) = factors(i / j) + factors(i)
factors(i) = 0
exit
end if
end do
Expand Down

0 comments on commit 41ce61c

Please sign in to comment.