Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Beginner FORTRAN Problem

  1. Jan 16, 2010 #1
    1. The problem statement, all variables and given/known data

    I am trying to find prime numbers that are i,i+2,i+6,i+8 apart. Could someone tell me the last set that this gives?

    2. Relevant equations


    3. The attempt at a solution

    program sieve_t
    implicit none
    integer*1 s(1000000), offset (10), sequence
    integer i, j, n


    do i=1, 10


    do i=1, 1000000
    s(i) = 1

    do i=2, 1000000
    if (s(i).eq.1) then
    do j=2, (1000000/i)

    do i=2, 1000000

    if (s(i).eq.1) then
    do j=1,sequence-1
    if (s(i+offset(j)).ne.1) goto 10
    write(*,*) n, i,i+2,i+6,i+8
    10 continue

  2. jcsd
  3. Jan 16, 2010 #2


    Staff: Mentor

    I'm not sure what you are asking. What does primes that are "i apart" mean? Are you asking for primes that differ by 0, 2, 6, and 8? Primes that differ by 0 aren't very interesting, since they would necessarily be equal. There are lots of primes that differ by 2, the first few pairs of which are 3 and 5, 5 and 7, and 11 and 13.

    Please clarify what you're trying to do.
  4. Jan 16, 2010 #3
    Sorry Mark44.

    I am looking for groups of primes. I am basically looking for prime quadruplets that differ by 2 and 6 and 8.

    For example {5, 7, 11, 13}
  5. Jan 16, 2010 #4


    Staff: Mentor

    OK, now I understand. One approach would be to first go through your array of 1,000,000 numbers looking for primes, using the sieve approach as you have been doing. After you have that array of 1s and 0s, then iterate through it looking for a 1. When you find a 1, check whether there is a 1 at position i + 2, i + 6, and i + 8. If there are 1s in all those positions, you have found a prime quadruplet.
  6. Jan 17, 2010 #5
    Could you compile it?
  7. Jan 17, 2010 #6


    Staff: Mentor

    Not sure I understand your question. I don't have a Fortran compiler. Did you try my suggestion and get compiler errors? Please clarify what you're asking.
  8. Jan 17, 2010 #7
    I think that my compiler has a bug in it, because it cannot even compile a correct code.

    Are there any online compilers?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook