Number.toEratosthenes v1.0

A prime number is a natural number greater than 1 that can be divided without remainder only by itself and by 1. Natural numbers n that can be divided by a number less than n and greater than 1 are composite numbers. Sieve of Eratosthenes identifies all prime numbers up to a given number n. The algorithm works as follows: write the numbers 1, 2, 3,4 ,..., n and will eliminate composites by marking them (initially all numbers are unmarked). This is exactly what the method does using bitwise operations.



Details

Author
Adrian Statescu
Current version
v1.0
GitHub
thinkphp/sieve-of-eratosthenes
Downloads
1656
Category
Native
Tags
Report
GitHub Issues

Releases


Dependencies

  • core/1.3: *

How to use

First you must to include the JS files in the head of your HTML document.

<script type="text/javascript" src="mootools.js"></script>
<script type="text/javascript" src="number.toEratosthenes.js"></script>

In your JavaScript code.

 
(function($){
    window.addEvent('domready',function(){
        $('f').addEvent('submit', function(e){
            if(e) {e.stop();}
            var n = $('n').get('value').toInt(); 
            if(!n) {return false;}
               var vec = [];
                   vec = (n).toEratosthenes(); 
               if(window.console){console.log(vec);} 
               var s = ''; 
                   for(var i=0;i<vec.length;i++) {
                       s += vec[i] + ', ';
                   } 
                   $('primenumbers').set('text',s);
         }); 
         $('f').fireEvent('submit');  
    });         
 })(document.id);

In your HTML code.

<form id="f" name="f">
<label for="n">N = </label><input type="text" id="n" value="100"/><input type="submit" value="go">
</form>  
<div id="primenumbers"></div>

Discuss

A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.

Found a bug in this plugin? Please report it this repository's Github Issues.

blog comments powered by Disqus