I'm not sure how to solve it if the input is negative, but if you assume the number is positive the answer would be easy
first, get the min factor of the first number but satisfy the condition x*(x+1) :
the factors of 6 are 1,2,3,6 so we take 2
for (int i = 1; i < a; i++)
if (a % i == 0 && i*(i+1)==a){
Console.Write( i );
break;
}
then find the max factor of the second number but satisfy the condition x*(x+1)
the factors of 20 are 1,2,4,5,10,20 so take 5
for (int i = b; i>=1; i--)
if (b % i == 0 && i*(i-1)==b){
Console.Write( i );
break;
}
the answer is 5-2=3
you can find factors of the number:
for (int i = 1; i <=a; i++)
if (a % i == 0)
Console.Write( i );
not sure about my answer, but I hope it helps.