public class Main {
public static void main
(String[] args
) { int n = 123;
for (int i = 1; i <= n; i++) {
if (isPrime(i)) {
if (n % i == 0) {
int j = n / i;
if (isPrime(j)) {
System.
out.
format("%d, %d%n", i, j
); }
}
}
}
}
static boolean isPrime(int n) {
if (n == 2) {
return true;
}
if (n < 2 || n % 2 == 0) {
return false;
}
for (int i
= 3; i
<= Math.
sqrt(n
); i
+= 2) { if (n % i == 0) {
return false;
}
}
return true;
}
}
CnB1YmxpYyBjbGFzcyBNYWluIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsKICAgICAgICBpbnQgbiA9IDEyMzsKICAgICAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKICAgICAgICAgICAgaWYgKGlzUHJpbWUoaSkpIHsKICAgICAgICAgICAgICAgIGlmIChuICUgaSA9PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgaW50IGogPSBuIC8gaTsKICAgICAgICAgICAgICAgICAgICBpZiAoaXNQcmltZShqKSkgewogICAgICAgICAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LmZvcm1hdCgiJWQsICVkJW4iLCBpLCBqKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICAKICAgIHN0YXRpYyBib29sZWFuIGlzUHJpbWUoaW50IG4pIHsKICAgICAgICBpZiAobiA9PSAyKSB7CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICBpZiAobiA8IDIgfHwgbiAlIDIgPT0gMCkgewogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIGZvciAoaW50IGkgPSAzOyBpIDw9IE1hdGguc3FydChuKTsgaSArPSAyKSB7CiAgICAgICAgICAgIGlmIChuICUgaSA9PSAwKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICB9Cn0K