What's the fastest way to do it?
My simple aproach:
for (C = 1;C<sqrt(A);C++) {
B=A/(C*(C+1));
if B is natural then add B,C to the list of possible pairs.
}
Can it be done in less than O(sqrt(A))?
Solution
As Egor Skriptunoff answers, it can be done easily in O(cube_root(A)).
Here is a simple javascript implementation.
function findBCs(A) {
if (A / 2 != Math.floor(A / 2)) return [];
var solution = [];
var i;
var SR3 = Math.pow(A, 1 / 3);
for (i = 1; i <= SR3; i++) {
var B, C;
C = i;
B = A / (C * (C + 1));
if (B == Math.floor(B)) {
solution.push([B, C]);
}
B = i;
C = (-1 + Math.sqrt(1 + 4 * A / B)) / 2;
if (C == Math.floor(C)) {
solution.push([B, C]);
}
}
return solution;
}
I accept Meh's answer because it should be better (besides it's implementation is a little more complex and I have not tested).