用ASP设计函数 判断一个大于2的整数是否为素数

来源:百度知道 编辑:UC知道 时间:2024/06/20 11:24:04
速速

<%
function isPN(lngTest)
dim i,k
k=clng(sqr(lngTest))
for i=2 to k
if lngTest mod k =0 then exit for
next
isPN=(i>k)
end function

If isPN(5) Then '这里的5是你要判断的数,任意换大于2的整数就可以了
Response.Write "素数"
Else
Response.Write "不是素数"
End If
%>

也许这个更适合你
<%
Dim x,flag
for x=2 to 100000
flag=0
x=cint(x)
if x <= 3 then
flag=0
else
if (x mod 2 = 0) then
flag=1
else
for i = 3 to x / 2
if x mod i = 0 then
flag=1
exit for
end if
next
end if
end if
if flag=1 then
Response.Write x & "不是质数"
else
Response.Write ""& x & "是质数"
end if
Response.Write "<br>"
next

%>