# thinkphp/sieve-of-eratosthenes

A method for Number Native MooTools, using sieve of Eratosthenes, identifies all prime numbers up to a given number n.
PHP JavaScript
Switch branches/tags
Nothing to show
Latest commit fc060fa Oct 30, 2010
 Failed to load latest commit information. Docs Oct 30, 2010 Source Oct 30, 2010 test README.md Oct 30, 2010 package.yml

# Number.toEratosthenes

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.

## How to use

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

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

``````#js
(function(\$){
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] + ', ';
}
});
\$('f').fireEvent('submit');
});
})(document.id);
``````

``````#html