You can find this amazing article from Microsoft MVP Emiliano Musso here, on TechNet Wiki:
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 http://smallbasic.com/. Once installed, you'll be ready to go.
Check out the different sections of this article:
Table of Contents
- Scope
- Factorization
- Requesting input
- Calculate primality
- Spotting factors
- Showing results
- Source code
- PNF on SmallBasic.com
- Bibliography
- See Also
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
To
Math.SquareRoot(divisor)
If
Math.Remainder(divisor, i) = 0
Then
isPrime = 0
Goto EndPrime
EndIf
EndFor
EndPrime:
PNF on SmallBasic.com
The source code from this article is available for testing and download at: http://smallbasic.com/program/?LLS908
Remember to head to the article for all the sections:
And special thanks to Emiliano for this great addition to the Small Basic library of content!
Small and Basically yours,
- Ninja Ed
See Also