static unsigned char primeTbl[999999999];
int main (void) {
int i, j;
//by sieve, all numbers except 1 and 0 are prime in the beginning;
for (i = 0; i < sizeof(primeTbl); i++)
primeTbl[i] = 1;
primeTbl[0] = 0;
primeTbl[1] = 0;
//the Sieve;
//for each number
for (i = 2; i < sizeof(primeTbl); i++)
{
//if this number is prime
if (primeTbl[i]!=0)
{
//we mark each of its multipliers as composite;
for (j = i + i; j < sizeof(primeTbl); j += i)
{
primeTbl[j] = 0;
}
}
}
int primeCounter=0;
//counting the primes;
for (i = 0; i < sizeof(primeTbl); i++) {
if(primeTbl[i]!=0){
primeCounter++;
}
}
//output.
printLineBreak();
printInteger(sizeof(primeTbl));
printLineBreak();
printInteger(primeCounter);
return 0;
}
function arrayOfPrimes(ceiling) {
var array = [2, 3];
for (var i = 5; i <= ceiling; i += 2) {
if (array.every(function(p) { return i % p; })) {
array.push(i);
}
}
return array;
}