Skip to content

Commit

Permalink
Attempt p7 in fortran (22)
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Oct 3, 2024
1 parent e1eb2b3 commit f8b1b2f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions fortran/src/include/primes.f90
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ end subroutine expand_sieve
! Function to set a bit to 0
subroutine clear_prime_bit(num)
integer(i18t), intent(in) :: num
integer(i18t) :: i, b
i = (num / bits_per_int) + 1
b = mod(num, bits_per_int)
print *, "Translating bit #", num, "to", i, b
is_prime(i) = iand(is_prime(i), ieor(-1_i18t, 2**b))
integer :: i
i = int((num / bits_per_int) + 1)
is_prime(i) = iand(is_prime(i), ieor(-1_i18t, 2**mod(num, bits_per_int)))
end subroutine clear_prime_bit

! Function to check if a bit is set
logical function get_prime_bit(num) result(bit)
integer(i18t), intent(in) :: num
bit = logical(btest(is_prime(num / bits_per_int + 1), mod(num, bits_per_int)))
integer :: i
i = int((num / bits_per_int) + 1)
bit = logical(btest(is_prime(i), mod(num, bits_per_int)))
end function get_prime_bit

end module primes
1 change: 1 addition & 0 deletions fortran/src/p0007.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ integer(i18t) function p0007() result(answer)
call expand_sieve(2_i18t**17)
do i = 0, 10001
answer = next_prime(answer)
print *, i, answer
end do
end function p0007
end module Problem0007

0 comments on commit f8b1b2f

Please sign in to comment.