I was given this question.
n = 77
n = p*q
p and q is a prime number
Make the finder of p and q with brute force.
My code so far:
public class If {
public static void main(String[] args) {
int p = 3, q = 3;
int n = 77;
int temp = p*q;
boolean flagp, flagq = false;
while (temp != n && p <= 77)
{
for(int i = 2; i <= p/2; ++i)
{
// condition for nonprime number
if(p % i == 0)
{
flagp = true;
break;
}
p = p+2;
q = 3;
for(int j = 2; j <= q/2; ++j)
{
// condition for nonprime number
if(q % j == 0)
{
flagq = true;
break;
}
q = q+2;
temp = p*q;
}
}
}
System.out.println(temp);
}
}
I was able to find the prime number checking. But I can't seem to find how loop it and find the matching p
and q
.