Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com What is the algorithm to compute the factorisation of an integer?

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 10-30-2006, 03:41 PM PM User | #1 laland New Coder   Join Date: Oct 2006 Posts: 12 Thanks: 0 Thanked 0 Times in 0 Posts What is the algorithm to compute the factorisation of an integer? Hi, I need some ideas on how to compute the factorisation of a non-zero integer? For example: if the user input is 8, its factorisation is 1 * 2 * 2 * 2; if the user input is -300, its factorisation is -1 * 2 * 2 * 3 * 5 * 5 Does anyone know? Thanks
 10-30-2006, 04:34 PM PM User | #2 Philip M Supreme Master coder!     Join Date: Jun 2002 Location: London, England Posts: 17,487 Thanks: 200 Thanked 2,470 Times in 2,448 Posts I have this in my library - I do not know where it came from. Number Factorer
Factor

Factorer

Factors of 44100 are 2 2 3 3 5 5 7 7

Previous Outputs

Calculating...

 10-30-2006, 04:57 PM PM User | #3 VortexCortex Regular Coder   Join Date: May 2005 Posts: 142 Thanks: 0 Thanked 0 Times in 0 Posts Yes, we do know. Show us what you've got so far and we'll help you out. P.S. the above script does not work in Netscape or FireFox. Last edited by VortexCortex; 10-30-2006 at 05:13 PM..
 10-30-2006, 05:04 PM PM User | #4 VortexCortex Regular Coder   Join Date: May 2005 Posts: 142 Thanks: 0 Thanked 0 Times in 0 Posts Well, while we're pasting code examples... Here's a script I wrote that returns an array of the factors so you can actually do something with them once the factoring is complete. PHP Code: ```             Prime Factors            function getFactors(num){            var n; //Variable to store the current number.            var f = new Array(); //Array to hold the factors.            if(!isNaN(n = parseInt(num, 10))&&(n != 0)){ //Convert n into an integer and make sure num is a number and non zero.                f[f.length] = n / (n = Math.abs(n)); //Make first element either 1 or -1 and convert n to a positive number for faster factoring.                var i = 2; //Variable to hold current factor.                while(i < n){                    if (n % i == 0){ //i is a factor of n                        n /= i; //divide n by its factor.                        f[f.length]=i; //store the factor.                        i = 2; //start over at factor of 2.                    } else if (i > 2) i+=2; //Avoid even numbers since 2 is the only even prime.                    else i=3; //try 3 as a factor.                }                f[f.length]=n; //i now equals n, therefore n is a factor of num.            }            return f; //return the array of factors.        }

Prime Factors

Number to factor:Get Factors      ``` Last edited by VortexCortex; 10-30-2006 at 05:08 PM.. Reason: added comments

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 10:35 PM.