M is the smallest possible sum for a set of four distinct primes such that the sum of any three is prime - (p1,p2,p3,p4}.
N is the smallest possible sum for a set of six distinct primes such that the sum of any five is prime - (q1,q2,q3,q4,q5,q6}.
Find M & N and the
corresponding sets.
M = 5 + 7 + 17 + 19 = 48
N = 5 + 7 + 11 + 19 + 29 + 37 = 108
program rs
c
c determine if any 3/4 primes and any 5/6 primes add to a prime
c
implicit none
integer p(140),topodds,sum3,sum4,sum5,sum6,
1 cnt,s3,s5,pp(6),i,j,ir,lim,ptest,j4,j6,i1,i2,i3,i4,i5,i6,
1 maxindex
topodds=740
maxindex=30
c make the primes that are less than "top"
p(1)=2
p(2)=3
cnt=2
do 100 i=5,topodds,2
lim=sqrt(1.*i)+1
do j=3,lim,2
ir=i/j
if (j*ir.eq.i)go to 100
enddo
cnt=cnt+1
if(cnt.eq.140)then
print*,' too many primes'
stop
endif
p(cnt)=i
100 enddo
do 1 i1=1,maxindex
pp(1)=p(i1)
do 2 i2=i1+1,maxindex
pp(2)=p(i2)
do 3 i3=i2+1,maxindex
pp(3)=p(i3)
do 4 i4=i3+1,maxindex
pp(4)=p(i4)
sum4=pp(1)+pp(2)+pp(3)+pp(4)
do 444 s3=1,4
sum3=sum4-pp(s3)
do ptest=4,maxindex
if(sum3.eq.p(ptest))go to 444
enddo
go to 500
444 enddo
if(sum4.le.48)print*,'*** ',(pp(j4),j4=1,4),sum4
500 do 5 i5=i4+1,maxindex
pp(5)=p(i5)
do 6 i6=i5+1,maxindex
pp(6)=p(i6)
sum6=pp(1)+pp(2)+pp(3)+pp(4)+pp(5)+pp(6)
do 666 s5=1,5
sum5=sum6-pp(s5)
do ptest=5,maxindex
if(sum5.eq.p(ptest))go to 666
enddo
go to 6
666 enddo
if(sum6.le.108)print*,'*****',(pp(j6),j6=1,6),sum6
6 enddo
5 enddo
4 enddo
3 enddo
2 enddo
1 enddo
end
Edited on February 6, 2019, 2:37 am