Question
4.27 (Pythagorean Triples) A right triangle can have sides that are all integers. The set of three integer values for the sides of a right
4.27 (Pythagorean Triples) A right triangle can have sides that are all integers. The set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of the squares of two of the sides is equal to the square of the hypotenuse. Find all Pythagorean triples for side1, side2, and the hypotenuse all no larger than 500. Use a triple-nested for loop that simply tries all possibilities. This is an example of brute-force computing. Its not aesthetically pleasing to many people. But there are many reasons why these techniques are important. First, with computing power increasing at such a phenomenal pace, so- lutions that would have taken years or even centuries of computer time to produce with the tech- nology of just a few years ago can now be produced in hours, minutes or even seconds. Recent microprocessor chips can process a billion instructions per second! Second, as youll learn in more advanced computer science courses, there are large numbers of interesting problems for which theres no known algorithmic approach other than sheer brute force. We investigate many kinds of problem-solving methodologies in this book. Well consider many brute-force approaches to vari- ous interesting problems.
SAMPLE RUN #0: ./pythagorean_triples
Interactive Session Standard Error (empty) Standard Output Hide Invisibles
Highlight: NoneStandard Input OnlyPrompts OnlyStandard Output w/o PromptsFull Standard OutputAllShow Highlighted Only
(3,4,5):9+16=25 (4,3,5):16+9=25 (5,12,13):25+144=169 (6,8,10):36+64=100 (7,24,25):49+576=625 (8,6,10):64+36=100 (8,15,17):64+225=289 (9,12,15):81+144=225 (9,40,41):81+1600=1681 (10,24,26):100+576=676 (11,60,61):121+3600=3721 (12,5,13):144+25=169 (12,9,15):144+81=225 (12,16,20):144+256=400 (12,35,37):144+1225=1369 (13,84,85):169+7056=7225 (14,48,50):196+2304=2500 (15,8,17):225+64=289 (15,20,25):225+400=625 (15,36,39):225+1296=1521 (15,112,113):225+12544=12769 (16,12,20):256+144=400 (16,30,34):256+900=1156 (16,63,65):256+3969=4225 (17,144,145):289+20736=21025 (18,24,30):324+576=900 (18,80,82):324+6400=6724 (19,180,181):361+32400=32761 (20,15,25):400+225=625 (20,21,29):400+441=841 (20,48,52):400+2304=2704 (20,99,101):400+9801=10201 (21,20,29):441+400=841 (21,28,35):441+784=1225 (21,72,75):441+5184=5625 (21,220,221):441+48400=48841 (22,120,122):484+14400=14884 (23,264,265):529+69696=70225 (24,7,25):576+49=625 (24,10,26):576+100=676 (24,18,30):576+324=900 (24,32,40):576+1024=1600 (24,45,51):576+2025=2601 (24,70,74):576+4900=5476 (24,143,145):576+20449=21025 (25,60,65):625+3600=4225 (25,312,313):625+97344=97969 (26,168,170):676+28224=28900 (27,36,45):729+1296=2025 (27,120,123):729+14400=15129 (27,364,365):729+132496=133225 (28,21,35):784+441=1225 (28,45,53):784+2025=2809 (28,96,100):784+9216=10000 (28,195,197):784+38025=38809 (29,420,421):841+176400=177241 (30,16,34):900+256=1156 (30,40,50):900+1600=2500 (30,72,78):900+5184=6084 (30,224,226):900+50176=51076 (31,480,481):961+230400=231361 (32,24,40):1024+576=1600 (32,60,68):1024+3600=4624 (32,126,130):1024+15876=16900 (32,255,257):1024+65025=66049 (33,44,55):1089+1936=3025 (33,56,65):1089+3136=4225 (33,180,183):1089+32400=33489 (34,288,290):1156+82944=84100 (35,12,37):1225+144=1369 (35,84,91):1225+7056=8281 (35,120,125):1225+14400=15625 (36,15,39):1296+225=1521 (36,27,45):1296+729=2025 (36,48,60):1296+2304=3600 (36,77,85):1296+5929=7225 (36,105,111):1296+11025=12321 (36,160,164):1296+25600=26896 (36,323,325):1296+104329=105625 (38,360,362):1444+129600=131044 (39,52,65):1521+2704=4225 (39,80,89):1521+6400=7921 (39,252,255):1521+63504=65025 (40,9,41):1600+81=1681 (40,30,50):1600+900=2500 (40,42,58):1600+1764=3364 (40,75,85):1600+5625=7225 (40,96,104):1600+9216=10816 (40,198,202):1600+39204=40804 (40,399,401):1600+159201=160801 (42,40,58):1764+1600=3364 (42,56,70):1764+3136=4900 (42,144,150):1764+20736=22500 (42,440,442):1764+193600=195364 (44,33,55):1936+1089=3025 (44,117,125):1936+13689=15625 (44,240,244):1936+57600=59536 (44,483,485):1936+233289=235225 (45,24,51):2025+576=2601 (45,28,53):2025+784=2809 (45,60,75):2025+3600=5625 (45,108,117):2025+11664=13689 (45,200,205):2025+40000=42025 (45,336,339):2025+112896=114921 (48,14,50):2304+196=2500 (48,20,52):2304+400=2704 (48,36,60):2304+1296=3600 (48,55,73):2304+3025=5329 (48,64,80):2304+4096=6400 (48,90,102):2304+8100=10404 (48,140,148):2304+19600=21904 (48,189,195):2304+35721=38025 (48,286,290):2304+81796=84100 (49,168,175):2401+28224=30625 (50,120,130):2500+14400=16900 (51,68,85):2601+4624=7225 (51,140,149):2601+19600=22201 (51,432,435):2601+186624=189225 (52,39,65):2704+1521=4225 (52,165,173):2704+27225=29929 (52,336,340):2704+112896=115600 (54,72,90):2916+5184=8100 (54,240,246):2916+57600=60516 (55,48,73):3025+2304=5329 (55,132,143):3025+17424=20449 (55,300,305):3025+90000=93025 (56,33,65):3136+1089=4225 (56,42,70):3136+1764=4900 (56,90,106):3136+8100=11236 (56,105,119):3136+11025=14161 (56,192,200):3136+36864=40000 (56,390,394):3136+152100=155236 (57,76,95):3249+5776=9025 (57,176,185):3249+30976=34225 (60,11,61):3600+121=3721 (60,25,65):3600+625=4225 (60,32,68):3600+1024=4624 (60,45,75):3600+2025=5625 (60,63,87):3600+3969=7569 (60,80,100):3600+6400=10000 (60,91,109):3600+8281=11881 (60,144,156):3600+20736=24336 (60,175,185):3600+30625=34225 (60,221,229):3600+48841=52441 (60,297,303):3600+88209=91809 (60,448,452):3600+200704=204304 (63,16,65):3969+256=4225 (63,60,87):3969+3600=7569 (63,84,105):3969+7056=11025 (63,216,225):3969+46656=50625 (63,280,287):3969+78400=82369 (64,48,80):4096+2304=6400 (64,120,136):4096+14400=18496 (64,252,260):4096+63504=67600 (65,72,97):4225+5184=9409 (65,156,169):4225+24336=28561 (65,420,425):4225+176400=180625 (66,88,110):4356+7744=12100 (66,112,130):4356+12544=16900 (66,360,366):4356+129600=133956 (68,51,85):4624+2601=7225 (68,285,293):4624+81225=85849 (69,92,115):4761+8464=13225 (69,260,269):4761+67600=72361 (70,24,74):4900+576=5476 (70,168,182):4900+28224=33124 (70,240,250):4900+57600=62500 (72,21,75):5184+441=5625 (72,30,78):5184+900=6084 (72,54,90):5184+2916=8100 (72,65,97):5184+4225=9409 (72,96,120):5184+9216=14400 (72,135,153):5184+18225=23409 (72,154,170):5184+23716=28900 (72,210,222):5184+44100=49284 (72,320,328):5184+102400=107584 (72,429,435):5184+184041=189225 (75,40,85):5625+1600=7225 (75,100,125):5625+10000=15625 (75,180,195):5625+32400=38025 (75,308,317):5625+94864=100489 (76,57,95):5776+3249=9025 (76,357,365):5776+127449=133225 (77,36,85):5929+1296=7225 (77,264,275):5929+69696=75625 (77,420,427):5929+176400=182329 (78,104,130):6084+10816=16900 (78,160,178):6084+25600=31684 (80,18,82):6400+324=6724 (80,39,89):6400+1521=7921 (80,60,100):6400+3600=10000 (80,84,116):6400+7056=13456 (80,150,170):6400+22500=28900 (80,192,208):6400+36864=43264 (80,315,325):6400+99225=105625 (80,396,404):6400+156816=163216 (81,108,135):6561+11664=18225 (81,360,369):6561+129600=136161 (84,13,85):7056+169=7225 (84,35,91):7056+1225=8281 (84,63,105):7056+3969=11025 (84,80,116):7056+6400=13456 (84,112,140):7056+12544=19600 (84,135,159):7056+18225=25281 (84,187,205):7056+34969=42025 (84,245,259):7056+60025=67081 (84,288,300):7056+82944=90000 (84,437,445):7056+190969=198025 (85,132,157):7225+17424=24649 (85,204,221):7225+41616=48841 (87,116,145):7569+13456=21025 (87,416,425):7569+173056=180625 (88,66,110):7744+4356=12100 (88,105,137):7744+11025=18769 (88,165,187):7744+27225=34969 (88,234,250):7744+54756=62500 (88,480,488):7744+230400=238144 (90,48,102):8100+2304=10404 (90,56,106):8100+3136=11236 (90,120,150):8100+14400=22500 (90,216,234):8100+46656=54756 (90,400,410):8100+160000=168100 (91,60,109):8281+3600=11881 (91,312,325):8281+97344=105625 (92,69,115):8464+4761=13225 (93,124,155):8649+15376=24025 (93,476,485):8649+226576=235225 (95,168,193):9025+28224=37249 (95,228,247):9025+51984=61009 (96,28,100):9216+784=10000 (96,40,104):9216+1600=10816 (96,72,120):9216+5184=14400 (96,110,146):9216+12100=21316 (96,128,160):9216+16384=25600 (96,180,204):9216+32400=41616 (96,247,265):9216+61009=70225 (96,280,296):9216+78400=87616 (96,378,390):9216+142884=152100 (98,336,350):9604+112896=122500 (99,20,101):9801+400=10201 (99,132,165):9801+17424=27225 (99,168,195):9801+28224=38025 (99,440,451):9801+193600=203401 (100,75,125):10000+5625=15625 (100,105,145):10000+11025=21025 (100,240,260):10000+57600=67600 (102,136,170):10404+18496=28900 (102,280,298):10404+78400=88804 (104,78,130):10816+6084=16900 (104,153,185):10816+23409=34225 (104,195,221):10816+38025=48841 (104,330,346):10816+108900=119716 (105,36,111):11025+1296=12321 (105,56,119):11025+3136=14161 (105,88,137):11025+7744=18769 (105,100,145):11025+10000=21025 (105,140,175):11025+19600=30625 (105,208,233):11025+43264=54289 (105,252,273):11025+63504=74529 (105,360,375):11025+129600=140625 (108,45,117):11664+2025=13689 (108,81,135):11664+6561=18225 (108,144,180):11664+20736=32400 (108,231,255):11664+53361=65025 (108,315,333):11664+99225=110889 (108,480,492):11664+230400=242064 (110,96,146):12100+9216=21316 (110,264,286):12100+69696=81796 (111,148,185):12321+21904=34225 (112,15,113):12544+225=12769 (112,66,130):12544+4356=16900 (112,84,140):12544+7056=19600 (112,180,212):12544+32400=44944 (112,210,238):12544+44100=56644 (112,384,400):12544+147456=160000 (112,441,455):12544+194481=207025 (114,152,190):12996+23104=36100 (114,352,370):12996+123904=136900 (115,252,277):13225+63504=76729 (115,276,299):13225+76176=89401 etc
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started