<%
const MAX=100
dim total
dim array(MAX) '存放所有小于给定数字的素数
dim a[MAX] '将N分解后得到的数字,它们的和等于N
dim r[MAX] '每一次分解后的余数
dim n,i
total=0 'total记录小于n的素数的个数
'这里假设需要分解的数字为n,你可以根据需要加一段代码即可实现用户输入
array(total)=1
'下面找出所有小于n的素数
for i=2 to n step 1
judgeit(i)
next
total=total+1
addit(n) '输出组成给定数的素数
sub addit(cal) 'cal=n
dim k,i
dim isitin
dim m,n,same
same=0
isitin=0
a(0)=r(0)=cal
k=1
do while(1)
if r(k-1)=0 then
for i=1 to k-1
if inarray(a(i)==0 then
isitin=0
endif
next
for m=1 to k-1
same=a[m]
for n=m+1 to k-1
if same=a[n] then
isitin=0
endif
next
next
if isitin=1 then
for i=1 to k-1
response.write a(i)
next
response.write "<br>"
endif
isitin=1
same=0
do while k>1 and a(k-1)=1
k--
wend
if k=1 then
exit do
endif
a(k-1)=a(k-1)-1
r(k-1)=r(k-1)+1
else
if r(k-1)<a(k-1) then
a(k)=r(k-1)
else
a(k)=a(k-1)
endif
r(k)=r(k-1)-a(k)
k=k+1
endif
wend
end sub
function inarray(temp)
dim i
for i=0 to total-1
if temp=arrar[i] then
inarray=1
exit function
endif
inarray=function
end function
sub judgeit(temp)
dim mn
dim judge=1
for mn=2 to temp-1
if (temp MOD mn)=0 then
judge=0
next
next
if judge=1 then
total=total+1
array(total)=temp
endif
end sub