Sieve
export function primes(num: number): number[] {
const numer: number[] = [];
for(let i=2; i<=num; i++){
if(Isprimes(i)){
numer.push(i);
}
}
return numer;
}
function Isprimes(num: number):boolean {
if(num ==1) return true;
if(num == 2 || num == 3) return true;
if( num % 2== 0 || num % 3 == 0) return false;
let i = 5;
while(num >= i*i){
if( num % i == 0 || num % (i+2) == 0 ) return false;
i +=6;
}
return true;
}
0
0
0.000
0 comments