- Clear["Global`*"];(*清除所有变量*)
- max=2000;(*边长的最大值*)
- nmax=1/2*(-1+Sqrt[-1+2*max]);(*由n^2+(n+1)^2<=max计算出来的n的最大值*)
- aa=Flatten[#,1]&@Table[Sort@{m^2-n^2,2*m*n,m^2+n^2},{n,1,nmax},{m,n+1,Sqrt[max-n^2]}];(*产生勾股数*)
- bb=Select[aa,GCD@@#==1&];(*选择互质*)
- cc=Sort[bb,#1[[3]]<#2[[3]]&](*按照第三列升序排列*)
复制代码
把你的代码肢解一下,并且添加上注释,这样更容易看明白、更好维护
- {{3,4,5},{5,12,13},{8,15,17},{7,24,25},{20,21,29},{12,35,37},{9,40,41},{28,45,53},{11,60,61},{33,56,65},{16,63,65},{48,55,73},{13,84,85},{36,77,85},{39,80,89},{65,72,97},{20,99,101},{60,91,109},{15,112,113},{44,117,125},{88,105,137},{17,144,145},{24,143,145},{51,140,149},{85,132,157},{119,120,169},{52,165,173},{19,180,181},{57,176,185},{104,153,185},{95,168,193},{28,195,197},{133,156,205},{84,187,205},{21,220,221},{140,171,221},{60,221,229},{105,208,233},{120,209,241},{32,255,257},{23,264,265},{96,247,265},{69,260,269},{115,252,277},{160,231,281},{161,240,289},{68,285,293},{207,224,305},{136,273,305},{25,312,313},{75,308,317},{204,253,325},{36,323,325},{175,288,337},{180,299,349},{225,272,353},{27,364,365},{76,357,365},{252,275,373},{135,352,377},{152,345,377},{189,340,389},{228,325,397},{40,399,401},{120,391,409},{29,420,421},{87,416,425},{297,304,425},{145,408,433},{203,396,445},{84,437,445},{280,351,449},{168,425,457},{261,380,461},{31,480,481},{319,360,481},{93,476,485},{44,483,485},{155,468,493},{132,475,493},{217,456,505},{336,377,505},{220,459,509},{279,440,521},{308,435,533},{92,525,533},{341,420,541},{33,544,545},{184,513,545},{165,532,557},{396,403,565},{276,493,565},{231,520,569},{48,575,577},{368,465,593},{240,551,601},{35,612,613},{105,608,617},{336,527,625},{429,460,629},{100,621,629},{200,609,641},{315,572,653},{300,589,661},{385,552,673},{52,675,677},{37,684,685},{156,667,685},{111,680,689},{400,561,689},{185,672,697},{455,528,697},{260,651,701},{259,660,709},{333,644,725},{364,627,725},{108,725,733},{407,624,745},{216,713,745},{468,595,757},{39,760,761},{481,600,769},{195,748,773},{273,736,785},{56,783,785},{432,665,793},{168,775,793},{555,572,797},{280,759,809},{429,700,821},{540,629,829},{41,840,841},{123,836,845},{116,837,845},{205,828,853},{232,825,857},{287,816,865},{504,703,865},{348,805,877},{369,800,881},{451,780,901},{60,899,901},{616,663,905},{464,777,905},{43,924,925},{533,756,925},{129,920,929},{215,912,937},{580,741,941},{301,900,949},{420,851,949},{615,728,953},{387,884,965},{124,957,965},{248,945,977},{473,864,985},{696,697,985},{372,925,997},{559,840,1009},{45,1012,1013},{660,779,1021},{496,897,1025},{64,1023,1025},{192,1015,1033},{315,988,1037},{645,812,1037},{320,999,1049},{620,861,1061},{731,780,1069},{495,952,1073},{448,975,1073},{132,1085,1093},{585,928,1097},{47,1104,1105},{744,817,1105},{576,943,1105},{264,1073,1105},{141,1100,1109},{235,1092,1117},{329,1080,1129},{423,1064,1145},{704,903,1145},{528,1025,1153},{765,868,1157},{68,1155,1157},{517,1044,1165},{204,1147,1165},{340,1131,1181},{611,1020,1189},{660,989,1189},{832,855,1193},{49,1200,1201},{147,1196,1205},{476,1107,1205},{245,1188,1213},{705,992,1217},{140,1221,1229},{612,1075,1237},{441,1160,1241},{280,1209,1241},{799,960,1249},{539,1140,1261},{420,1189,1261},{748,1035,1277},{637,1116,1285},{893,924,1285},{560,1161,1289},{72,1295,1297},{51,1300,1301},{255,1288,1313},{735,1088,1313},{360,1271,1321},{357,1276,1325},{884,987,1325},{833,1056,1345},{504,1247,1345},{561,1240,1361},{840,1081,1369},{148,1365,1373},{931,1020,1381},{663,1216,1385},{296,1353,1385},{53,1404,1405},{444,1333,1405},{159,1400,1409},{265,1392,1417},{792,1175,1417},{371,1380,1429},{592,1305,1433},{477,1364,1445},{76,1443,1445},{228,1435,1453},{583,1344,1465},{936,1127,1465},{740,1269,1469},{380,1419,1469},{969,1120,1481},{689,1320,1489},{532,1395,1493},{55,1512,1513},{888,1225,1513},{165,1508,1517},{795,1292,1517},{684,1363,1525},{156,1517,1525},{385,1488,1537},{312,1505,1537},{901,1260,1549},{495,1472,1553},{1036,1173,1565},{836,1323,1565},{1007,1224,1585},{624,1457,1585},{715,1428,1597},{80,1599,1601},{240,1591,1609},{988,1275,1613},{780,1421,1621},{57,1624,1625},{1113,1184,1625},{285,1612,1637},{399,1600,1649},{560,1551,1649},{935,1368,1657},{1140,1219,1669},{720,1519,1681},{627,1564,1685},{164,1677,1685},{1045,1332,1693},{328,1665,1697},{741,1540,1709},{1092,1325,1717},{492,1645,1717},{880,1479,1721},{1155,1292,1733},{59,1740,1741},{177,1736,1745},{656,1617,1745},{295,1728,1753},{413,1716,1765},{84,1763,1765},{969,1480,1769},{1040,1431,1769},{1248,1265,1777},{531,1700,1781},{820,1581,1781},{420,1739,1789},{649,1680,1801},{767,1656,1825},{984,1537,1825},{885,1628,1853},{172,1845,1853},{61,1860,1861},{183,1856,1865},{344,1833,1865},{305,1848,1873},{1148,1485,1877},{427,1836,1885},{1003,1596,1885},{924,1643,1885},{516,1813,1885},{1311,1360,1889},{549,1820,1901},{688,1785,1913},{671,1800,1921},{1121,1560,1921},{1092,1595,1933},{1312,1425,1937},{88,1935,1937},{793,1776,1945},{264,1927,1945},{860,1749,1949},{1239,1520,1961},{440,1911,1961},{915,1748,1973},{63,1984,1985},{616,1887,1985},{1032,1705,1993},{315,1972,1997}}
复制代码 |