// find all primes < 1Musing BRUTE FORCE, checking // ALL whole numbers less tha
ID: 3616265 • Letter: #
Question
// find all primes < 1Musing BRUTE FORCE, checking
// ALL whole numbers less than square root as possible
// factors of 'n'
public class Lab1
{
staticintc=0; //MINE
static int array[] = newint[1000000]; //MINE
publicstatic boolean isPrime(int n)
{
int root = (int)Math.sqrt(n);
for(int i=2; i<=root; i++)
{
// if(n%i==0) //Original
if ((n%array[c]) ==0) //MINE
{
return false;
}
}
return true;
}
publicstatic void main(String args[])
{
long start, end,mstime;
start =System.currentTimeMillis();
for(int i=2; i<1000000; i++)
{
if (isPrime(i))
{
System.out.println(i);
array[c] =i; //MINE
c++; //MINE
}
}
end =System.currentTimeMillis();
mstime = end -start;
System.out.println("#primes = " + c + ", mstime = " + mstime);
}
}
THE MAIN GOAL OF THE PROJECT IS TO EDIT THE CODESO THAT THE PROGRAM DOES THE SAME THING, JUST IN A FRACTION OF THETIME. DIVIDING THE INCREMENTED NUMBER BY 2,3, PRIME NUMBER, NEXTPRIME NUMBER, NEXT PRIME NUMBER AND SO ON.
Explanation / Answer
please rate - thanks had to change the output too public class untitled { static intc=0; //MINE static int array[] = newint[1000000]; //MINE public static boolean isPrime(int n) { int root = (int)Math.sqrt(n); for (int i=2;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.