Prime Numbers

So, as you know from previous posts, I’m a geek. That means i like to do geeky things and then tell people. What do i have this time you ask? Why its a list of prime number up to and including 1005833, not counting 1(it was slightly more effort than i wanted to put in to this). Yeah, so i got bored and wrote the little program below in java to generate this. I decided to run it on my file/web server here. Its a 2.6 ghz pentium 4 with hyperthreading and it took about 4.5 hours to generate these.

public class CountPrime
{
public static void main(String[] args)
{
for(long i=1;i<30000000;i=i+2)
{
for(long j=i-1;j>1;j--)
{
if(i%j==0) break;
if(j==2) System.out.println(i);
}
}	}
}

This bring me to a little mini-rant. Notice how i’m using longs in the code above? Why not just do something smart and use unsigned integers giving you a nice 2^32 long space to work with? Well here’s the answer. JAVA DOESN’T FREAKING SUPPORT UNSIGNED ANYTHING!!!! I took 2 classes on java and never heard a word about this. I’ve defended java from idiots that for some reason like c or c++ without knowing this. How do you freaking design a programming language without support for something so unbelievable basic as unsigned integers or short or chars or bytes or longs or anything like that?

Ok, that was a little more than a mini-rant but i feel better now. Anywho, here are the list of prime numbers. The file is tar’ed and gzip’ed so if you’re using the only os in the world that doesn’t support it built-in (windows), its time to upgrade to something ‘nix based.

Related Posts