-2

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;
}
mch
  • 9,424
  • 2
  • 28
  • 42
John Wick
  • 37
  • 4
  • 1
    you would need something that can handle big integers. See for example [Big integer in C or C++](http://stackoverflow.com/questions/4827538/big-integer-in-c-or-c) – Klas Lindbäck Oct 12 '15 at 06:43

1 Answers1

2

You need an implementation of a Big Integer in C, as your predicted Results can get higher than the normal Integer, even the long long int is capable of storing. You can either write one yourself or use one that has already been written, like here.

Community
  • 1
  • 1
Magisch
  • 7,312
  • 9
  • 36
  • 52