2楼贴图代码已经是最短;没有更短的了;
看下VB的代码:
'获取不大于某个正整数的最大的素数
Private Function MaxINT(iInt As Integer) As Integer
Dim i As Integer, i1 As Integer For i1 = iInt To 2 Step -1
For i = 2 To iInt
If (i1 Mod i) = 0 Then Exit For
Next
If i = i1 Then MaxINT = i1: Exit For
Next
End Function