VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 6585
ClientLeft = 60
ClientTop = 345
ClientWidth = 11130
LinkTopic = "Form1"
ScaleHeight = 6585
ScaleWidth = 11130
StartUpPosition = 2 '屏幕中心
WindowState = 2 'Maximized
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_DblClick()
k = 0
Cls
For i = 1 To 59
For j = i + 1 To 59
'这儿保证不重复,非等腰
If (i + j + 60) Mod 3 = 0 Then
'这儿保证三边之和整除3
If i + j > 60 And i + 60 > j And j + 60 > i Then
'这儿保证是个合法三角形
k = k + 1'计数
Print k & ": " & i & " , " & j & " ," & 60, '输出详细
If k Mod 5 = 0 Then Print '5个换一行
End If
End If
Next
Next
Print '终止一行 使后面的输出在新行开始
Print "此类三角形共有: " & k & "个" ''输出最终结果
End Sub
'请将以上内容复制 到记事本中 以 .frm 为扩展名 保存, 然后用VB打开运行双击 就可以产生所要的结果.
'共271个
Dim a As Integer
Dim b As Integer
Dim n As Integer
n = 0
For a = 2 To 59
For b = 61 To 60 + a
If (60 + a + b) Mod 3 = 0 Then
n = n + 1
End If
Next b
Next a
Print n
结果:590