Skip to main content
Changing 1 million to 999984 to save a byte
Source Link
Vasu Adari
  • 979
  • 7
  • 17

Ruby, 118118 117 bytes

n=1000000;t=true;a=[t]*n;n=999984;t=true;a=[t]*n;(2..Math.sqrt(n).round).each{|i|a[i]&&(i..n/i).each{|j|a[j*i]=!t}};(2..n).each{|i|a[i]&&p(i)}

Run Time:

0.54s53s user 0.13s system 89%92% cpu 0.752714 total

Ruby, 118 bytes

n=1000000;t=true;a=[t]*n;(2..Math.sqrt(n).round).each{|i|a[i]&&(i..n/i).each{|j|a[j*i]=!t}};(2..n).each{|i|a[i]&&p(i)}

Run Time:

0.54s user 0.13s system 89% cpu 0.752 total

Ruby, 118 117 bytes

n=999984;t=true;a=[t]*n;(2..Math.sqrt(n).round).each{|i|a[i]&&(i..n/i).each{|j|a[j*i]=!t}};(2..n).each{|i|a[i]&&p(i)}

Run Time:

0.53s user 0.13s system 92% cpu 0.714 total
Source Link
Vasu Adari
  • 979
  • 7
  • 17

Ruby, 118 bytes

n=1000000;t=true;a=[t]*n;(2..Math.sqrt(n).round).each{|i|a[i]&&(i..n/i).each{|j|a[j*i]=!t}};(2..n).each{|i|a[i]&&p(i)}

Run Time:

0.54s user 0.13s system 89% cpu 0.752 total