import
java.math.*;
import
java.util.*;
class
Solution {
public
static
BigInteger sqrtF(BigInteger x)
throws
IllegalArgumentException
{
if
(x.compareTo(BigInteger.ZERO) <
0
) {
throw
new
IllegalArgumentException(
"Negative argument.");
}
if
(x.equals(BigInteger.ZERO)
|| x.equals(BigInteger.ONE)) {
return
x;
}
BigInteger two
= BigInteger.valueOf(2L);
BigInteger y;
y = x.divide(two);
while
(y.compareTo(x.divide(y)) >
0
)
y = ((x.divide(y)).add(y))
.divide(two);
return
y;
}
public
static
BigInteger sqrtC(BigInteger x)
throws
IllegalArgumentException
{
BigInteger y = sqrtF(x);
if
(x.compareTo(y.multiply(y)) ==
0
) {
return
y;
}
else
{
return
y.add(BigInteger.ONE);
}
}
static
String FermatFactors(BigInteger n)
{
BigInteger ONE =
new
BigInteger("
1
");
BigInteger ZERO =
new
BigInteger("
0
");
BigInteger TWO =
new
BigInteger("
2
");
if
(n.mod(TWO).equals(ZERO)) {
return
n.divide(TWO)
.toString()
+ ",
2
";
}
BigInteger a = sqrtC(n);
if
(a.multiply(a).equals(n)) {
return
a.toString()
+ ", " + a.toString();
}
BigInteger b;
while
(
true
) {
BigInteger b1 = a.multiply(a)
.subtract(n);
b = sqrtF(b1);
if
(b.multiply(b).equals(b1))
break
;
else
a = a.add(ONE);
}
return
a.subtract(b).toString()
+ ", " + a.add(b).toString();
}
public
static
void
main(String args[])
{
String N = "
105327569
";
System.out.println(
FermatFactors(
new
BigInteger(N)));
}
}