If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p ≤ 1000, is the number of solutions maximized?
Source: Project Euler
I get p=840 with 8 solutions
a b c p
---------------------------------------------------
56 390 394 840
140 336 364 840
40 399 401 840
168 315 357 840
210 280 350 840
120 350 370 840
105 360 375 840
240 252 348 840
program z
implicit none
integer a,b,c,c2,cnt,par(4,2500),
1 i,j,dum(4),best(4,20),
1 dups_old,dups_new,old_p,k,oldcnt,cntr,kk,ptest
real x
cntr=0
do 4 a=1,1000
do b=a+1,1000
c2=a**2+b**2
x=sqrt(1.*c2)
c=sqrt(1.*c2)
if(abs(x-c).lt.0.001) then
ptest=a+b+c
if(ptest.gt.1000)go to 4
cntr=cntr+1
par(1,cntr)=a
par(2,cntr)=b
par(3,cntr)=c
par(4,cntr)=a+b+c
endif
enddo
4 enddo
do i=1,cntr-1
do j=i+1,cntr
if(par(4,i).gt.par(4,j))then
do kk=1,4
dum(kk)=par(kk,j)
par(kk,j)=par(kk,i)
par(kk,i)=dum(kk)
enddo
endif
enddo
enddo
dups_old=1
dups_new=1
old_p=1
do cnt=1,cntr
if(par(4,cnt).eq.old_p)then
dups_new=dups_new+1
else
old_p=par(4,cnt)
if(cnt.ne.1.and.dups_new.ge.dups_old)then
dups_old=dups_new
do k=1,dups_new
oldcnt=cnt-k
do j=1,4
best(j,k)=par(j,oldcnt)
enddo
enddo
endif
dups_new=1
endif
enddo
do i=dups_old,1,-1
print *,(best(j,i),j=1,4)
enddo
end
If you allow the perimeter to go to 6000 I get
p=5040 with 16 answers:
1440 1512 2088 5040
990 1904 2146 5040
336 2340 2364 5040
1008 1890 2142 5040
504 2240 2296 5040
315 2352 2373 5040
140 2448 2452 5040
1365 1584 2091 5040
630 2160 2250 5040
240 2394 2406 5040
720 2100 2220 5040
1120 1800 2120 5040
1071 1840 2129 5040
840 2016 2184 5040
560 2205 2275 5040
1260 1680 2100 5040
Edited on December 8, 2018, 2:47 pm