Blog Post

Small Basic Blog
2 MIN READ

Prime Number Factorization - Small Basic Featured Article

Ed Price's avatar
Ed Price
Silver Contributor
Feb 13, 2019
First published on MSDN on Sep 28, 2015

Authored by Ed Price


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 http://smallbasic.com/ . 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 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:


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





Published Feb 13, 2019
Version 1.0
No CommentsBe the first to comment