So am studying cryptography and in cryptography we deal with prime numbers and am sure there many way to get prime numbers but i thought i implement Sieve of Eratosthenes wiki
https://en.wikipedia.org/wiki/Sieve_of_EratosthenesHere is my code in python and also Java:
Python sampleprint"*****************************************************"
print"\t\tSieve of Eratosthenes"
print"*****************************************************"
num=raw_input("||Enter a number:")
num=int(num)
result=range(2,num)
print"||-----------------------------"
print"||Prime numbers between 0-",num
print"||-----------------------------"
for i in result:
for j in result:
if j!=i and j%i==0:
result.pop(result.index(j))
print "||PRIME NUMBERS:",result
print"||------------------------------"
print"*****************************************************"
Java sampleimport java.util.Scanner;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
class PrimeNo{
public static void main(String... args){
int num;
Scanner input=new Scanner(System.in);
System.out.println("***********************************************");
System.out.println("\t\tSieve of Eratosthenes");
System.out.println("***********************************************");
System.out.println("||Find Prime Numbers");
System.out.println("||---------------------------------------------");
System.out.print("||Enter range:");
num=input.nextInt();
List<Integer> range=new CopyOnWriteArrayList<Integer>();
for(int i=2;i<num;i++)
{
range.add(i);
}
for(int i:range)
{
for(int j:range)
{
if(j!=i && j%i==0)
{
range.remove(range.indexOf(j));
}
}
}
System.out.println("||---------------------------------------------");
System.out.println("||---------------------------------------------");
System.out.println("||PRIME NOs:"+range);
System.out.println("||---------------------------------------------");
System.out.println("||---------------------------------------------");
System.out.println("***********************************************");
System.out.println("***********************************************");
}
}