consider x^i+y^i=z^i
, x<=y<=z<=m
and 2<=i<=n
(m and n are inputs)
m can vary from 5 to 100
n can vary from 2 to 100
How can i aproach this problem.? I've a solution but it's not feasible for values of n and m like 80 or more and starts giving wrong results :(
int main()
{
int m, n;
long long int x, y, z, j;
long long int xe, ye, ze, se;
long long int sum = 0;
scanf("%d", &m);
scanf("%d", &n);
for (j = 2; j <= n; j++)
{
for (x = 0; x <= m; x++)
{
for (y = x; y <= m; y++)
{
for (z = y; z <= m; z++)
{
xe = pow(x, j);
ye = pow(y, j);
ze = pow(z, j);
se = (xe + ye);
if (ze == se)
{
printf("\n i = %lld", j);
sum++;
}
}
}
}
}
printf("sum= %lld ", sum);
return 0;
}