Simple Windows application to compute prime numbers

• Jul 8th 2010, 11:27 PM
gruendike
Simple Windows application to compute prime numbers
I know this program isn't groundbreaking but after looking at simple prime number calculators online I decided to create my own. On my machine I was able to enter numbers as high as 18 or 19 digits (although you don't want a very large range!). My website is completely unknown so I was just hoping for some feedback on this, and possibly making it known to anyone who may find it handy.

It runs on Windows and requires .NET framework 2.0 or greater. As long as you have an updated version of Windows it should work (Tongueout)

Attachment 18143
• Jul 9th 2010, 12:18 AM
Also sprach Zarathustra
The program in JAVA:

[PHP]import java.util.Scanner;
public class Primes {
public static void main (String[]args){
Scanner input=new Scanner(System.in);

System.out.print("Enter two numbers");
int num1=input.nextInt();
int num2=input.nextInt();
Boolean isPrime=true;
for(int i=num1; i<num2; i++){
for(int j=2; j<=(int)Math.sqrt(i) && isPrime; j++){
if(i%j==0)
isPrime=false;}
if(isPrime==true)
System.out.print(i);
isPrime=true;
}
}
}

[/PHP]
• Jul 9th 2010, 12:21 AM
undefined
I think it's cool, thanks for sharing. For people interested in the underlying algorithm, this is commonly known as a segmented sieve. To the OP: You might have fun programming a segmented Euler phi sieve (using a prime sieve to get values of Euler phi for some larger integers)...

@Also sprach Zarathustra: That's trial division and generally much slower, except for certain inputs.
• Jul 9th 2010, 12:28 AM
Also sprach Zarathustra
Yes, I know... (just for fun...)
• Jul 9th 2010, 01:03 AM
gruendike
Quote:

Originally Posted by Also sprach Zarathustra
The program in JAVA:

Cool. I actually first wrote this in Java but converted it to Visual Basic as a means to help me start learning it. I also added a feature which calculates the range in 5000 number increments to avoid very large arrays being addressed in memory.