- #1
ƒ(x) → ∞
- 25
- 0
Homework Statement
I have been trying to come up with a program to calculate twin primes using a sieve algorithm in Fortran. So far I have been successful in creating one that finds primes, but I am having difficulty finding one that finds prime twins. If I knew how to do this I could find prime quadruplets!
Homework Equations
-
The Attempt at a Solution
My sieve program is running perfectly, however having run the twin primes program through debugger was not as successful. It is finding what appear to be random numbers. Can anybody help?
My intial idea was to find prime numbers that differ by two.
program prime twins
implicit none
integer*1 s(100000)
integer i, j, n
n=0
do i=1, 100000
s(i) = 1
enddo
do i=2, 100000
if (s(i).eq.1) then
do j=2, (100000/i)
s(i*j)=0
enddo
endif
enddo
do i=2, 100000
if (s(i).eq.s(i+2).eq.1) then
n=n+1
write(*,*,*) n,i,i+2
endif
endo
end
Last edited: