C First occurrence of a string of exactly n consecutive twin prime pairs C Hugo Pfoertner, http://www.pfoertner.org/ C C Oct 15 2003 Initial version logical isprim, prime C C Set m = 4 + 2*(target number of twin pairs) C...+....1....+....2....+....3....+....4....+....5....+....6....+....7.. C Examples: m=10 for OEIS A035791, m=8 for A035790, m=6 for A035789 C parameter (m=10) integer p(m) C Primality checker from C http://www.enginemonitoring.net/math/isprim.txt external isprim c p(1) = 3 p(2) = 5 p(3) = 7 p(4) = 11 p(5) = 13 p(6) = 17 c j = 6 do 10 i = 19, 101, 2 if ( isprim(i) ) then j = j + 1 if ( j .gt. m ) goto 20 p(j) = i endif 10 continue 20 continue c found = 0 do 100 i = p(m)+2, 2147483647, 2 if ( isprim(i) ) then do 110 j = 1, m p(j) = p(j+1) 110 continue p(m) = i c Preceding adjacent two primes must not be twin primes if ( p(2)-p(1) .eq. 2 ) goto 100 c Check for consecutive twin pairs do 120 k = 3, m-3, 2 if ( p(k+1)-p(k) .ne. 2 ) goto 100 120 continue c Following adjacent two primes must not be twin primes if ( p(m)-p(m-1) .eq. 2 ) goto 100 c found = found + 1 write (*,1000) (p(l),l=3,m-2) C Adjust format for m>12 1000 format ( 8i10 ) C Stop after 100 occurrences if ( found .gt. 100 ) stop c endif 100 continue end