Algorithm of prime number generator [Asp Edtion]

Source: Internet
Author: User
1 <%

2 function calcprimes (intprimeubound)

3 'intprimeubound is the upper limit to calculate the prime number

4 dim I, j

5 Dim strtmp

6 dim bitarray

7
8 redim bitarray (intprimeubound + 1)

9
10 for I = 0 to intprimeubound

11 bitarray (I) = 1

12 next

13

14 for I = 2 to CINT (sqr (intprimeubound ))

15 if 1 = bitarray (I) then

16 J = I

17 while J * I <= intprimeubound

18 bitarray (I * j) = 0

19 J = J + 1

20 Wend

21 end if

22 next

23
24 for I = 2 to intprimeubound

25 if 1 = bitarray (I) then

26 strtmp = strtmp & CSTR (I )&","

27 end if

28 next

29

30 if strtmp <> "" then

31 strtmp = left (strtmp, Len (strtmp)-1)

32 calcprimes = Split (strtmp ,",")

33 else

34 calcprimes = ""

35 end if

36

37 end Function

38%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.