x y z a b 4 3 5 3 1 8 15 17 5 3 12 5 13 5 1 12 35 37 7 5 20 21 29 7 3 24 7 25 7 1 16 63 65 9 7 28 45 53 9 5 40 9 41 9 1 20 99 101 11 9 36 77 85 11 7 48 55 73 11 5 56 33 65 11 3 60 11 61 11 1 24 143 145 13 11 44 117 125 13 9 60 91 109 13 7 72 65 97 13 5 80 39 89 13 3 84 13 85 13 1 28 195 197 15 13 52 165 173 15 11 88 105 137 15 7 112 15 113 15 1 32 255 257 17 15 60 221 229 17 13 84 187 205 17 11 104 153 185 17 9 120 119 169 17 7 132 85 157 17 5 140 51 149 17 3 144 17 145 17 1 36 323 325 19 17 68 285 293 19 15 96 247 265 19 13 120 209 241 19 11 140 171 221 19 9 156 133 205 19 7 168 95 193 19 5 176 57 185 19 3 180 19 181 19 1 40 399 401 21 19 76 357 365 21 17 136 273 305 21 13 160 231 281 21 11 208 105 233 21 5 220 21 221 21 1 44 483 485 23 21 84 437 445 23 19 120 391 409 23 17 152 345 377 23 15 180 299 349 23 13 204 253 325 23 11 224 207 305 23 9 240 161 289 23 7 252 115 277 23 5 260 69 269 23 3 264 23 265 23 1 48 575 577 25 23 92 525 533 25 21 132 475 493 25 19 168 425 457 25 17 228 325 397 25 13 252 275 373 25 11 272 225 353 25 9 288 175 337 25 7 308 75 317 25 3 312 25 313 25 1 52 675 677 27 25 100 621 629 27 23 184 513 545 27 19 220 459 509 27 17 280 351 449 27 13 304 297 425 27 11 340 189 389 27 7 352 135 377 27 5 364 27 365 27 1 56 783 785 29 27 108 725 733 29 25 156 667 685 29 23 200 609 641 29 21 240 551 601 29 19 276 493 565 29 17 308 435 533 29 15 336 377 505 29 13 360 319 481 29 11 380 261 461 29 9 396 203 445 29 7 408 145 433 29 5 416 87 425 29 3 420 29 421 29 1 ------------------------------------- 'ピタゴラス数 x, y, z で、x が偶数のみ Option Explicit Sub main() Const LIMIT = 30 Dim x As Integer, y As Integer, z As Integer Dim a As Integer, b As Integer, count As Integer, tmp As Integer Cells(1, 1).Value = "x" Cells(1, 2).Value = "y" Cells(1, 3).Value = "z" Cells(1, 4).Value = "a" Cells(1, 5).Value = "b" count = 1 For a = 3 To LIMIT Step 2 For b = a - 2 To 1 Step -2 If gcm(a, b) = 1 Then count = count + 1 x = (a * a - b * b) / 2 y = a * b z = (a * a + b * b) / 2 Cells(count, 1).Value = x Cells(count, 2).Value = y Cells(count, 3).Value = z Cells(count, 4).Value = a Cells(count, 5).Value = b End If Next b Next a End Sub Function gcm(a As Integer, b As Integer) '最大公約数を求めて返す関数:ユークリッドの互除法を使用 Dim r As Integer '関数内部で使う変数 If (a < b) Then gcm = gcm(b, a) '再帰呼び出し Else r = a Mod b 'Mod は割り算の余りを返す演算子 If r = 0 Then gcm = b Else gcm = gcm(b, r) '再帰呼び出し End If End If End Function