Prime Number Factorization - Small Basic Featured Article

You can find this amazing article from Microsoft MVP Emiliano Musso here, on TechNet Wiki:

             Prime Number Factorization with Small Basic


In this article, Emiliano takes you through a simple method to factorize a number into its prime factors. It uses Small Basic, which can be downloaded at Once installed, you'll be ready to go.


Check out the different sections of this article:

Table of Contents




Let's include one example of the code used. This is to...

Calculate primality

We've seen above that to check if a number is prime, we need to test its divisors up to the square root of the number itself. We must test each of those divisors, checking if the division give back no remainders. That can be done as follows:

' -- Test for primality of current divisor

isPrime = 1

For i = 2 ``ToMath.SquareRoot(divisor)

If Math.Remainder(divisor, i) = 0 ``Then

isPrime = 0

Goto EndPrime





PNF on

The source code from this article is available for testing and download at:          


Remember to head to the article for all the sections:

             Prime Number Factorization with Small Basic


And special thanks to Emiliano for this great addition to the Small Basic library of content!


Small and Basically yours,

   - Ninja Ed


See Also