# 39. 素数之积RSA加密算法
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on('line', function(num) {
num = parseInt(num);
if (isPrime(num)) {
console.log('-1 -1');
return;
}
for(let i=2; i<=Math.sqrt(num); i++) {
if (num % i === 0) {
let j = num/i;
if (isPrime(i) && isPrime(j)) {
console.log(i < j ? i+' '+j : j+' '+i);
return;
}
}
}
console.log('-1 -1');
})
function isPrime(num) {
let isSu = true;
for(let i=2; i<num-1; i++) {
if(num % i === 0) {
isSu = false;
break;
}
}
return isSu;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34