I have equation: x + y + xy = n. And my code:
#include <iostream>
#include <cstring>
using namespace std;
long c;
int main()
{
long x = 0;
cin >> c;
if(c == 0)
{
cout << 1 << endl;
return 0;
}
for(long i = 1; i <= c / 2; i ++)
{
for(long j = 1; j <= c; j ++)
if(i + j + i * j == c)
{
x ++;
break;
}
}
cout << x + 2 << endl;
}
Of course this code is very slow. How can i find positive number of solutions in faster way? Maybe there is specific algorithm?