DimiPetrov

Primes to N

Jan 10th, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. const input = ['24'];
  2.  
  3. const print = this.print || console.log;
  4. const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  5.  
  6. const n = +gets();
  7. let primes = [];
  8. primes.push(1);
  9. primes.push(2);
  10.  
  11. for (let i = 3; i <= n; i++) {
  12. primes.push(i);
  13. for(let j = 2; j < i; j++) {
  14. if(i % j == 0) {
  15. primes.pop();
  16. break;
  17. }
  18. }
  19. }
  20.  
  21. print(primes.join(' '));
Advertisement
Add Comment
Please, Sign In to add comment