考虑x + y ^ ^我= z ^我x

时间:2023-01-17 11:42:41

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

考虑x + y ^ ^我= z ^我x < = y z < = m和2 < < = =我< = n(m和n输入)m也从5到100 n 2到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 :(

我该如何解决这个问题?我有一个解,但对于n和m的值不可能达到80或更多,并开始给出错误的结果

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;
}

1 个解决方案

#1


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.

您需要在C中实现一个大整数,因为您的预测结果可以比正常整数更高,甚至长时间的int也可以存储。你可以自己写,也可以用已经写好的,比如这里。

#1


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.

您需要在C中实现一个大整数,因为您的预测结果可以比正常整数更高,甚至长时间的int也可以存储。你可以自己写,也可以用已经写好的,比如这里。