Increasing the capacity of an int - C

Asked

Viewed 26 times

0

When trying to calculate which prime can do a 0 rest split with the number 600851475143, I get the error Segmentation fault with the following script:

int count_1 = 0, count_2 = 0, soma = 0, maior = 0;
  int numero_maximo[600851475144];

  for (count_1 = 2; count_1 <= 600851475143; count_1++)
  {
    numero_maximo[count_1] = count_1;
  }

  for (count_1 = 2; count_1 <= 600851475143; count_1++)
  {
    if (numero_maximo[count_1] == count_1)
    {
      if (600851475143 % count_1 == 0)
      {

        if (count_1 > maior)
        {
          maior = 0;
          maior = count_1;
        }
      }

    }
  }

Although it used long long and usigned to increase the capacity of the int, the error still persists, since int does not support the value I need to pass. I tried using dynamic allocation but was not very happy.

  • 1

    The maximum value you can store in a long long is 9223372036854775807 which is much higher than your 600851475143. Your error is another, review your variable statements, but note that you are doing nonsense like this array with the sequence of integer numbers from 0 to 600851475143.

  • @anonymity, can point out what’s wrong?

  • If you want to calculate the largest cousin less or equal to 600851475143 wouldn’t it be wiser to start from it and pick up the previous ones until you find a cousin than to start from 2 and go calculating until you find the maximum? Also your primality calculation is wrong.

  • @anonym your first remark for pertinent. As for the second, I used the Aesthetes sieve with a useful modification, I don’t see how it could be wrong, but I appreciate the help.

  • How you used the Eratosthene Sieve if you store it all integers from 0 to 600851475144 and not just primes already calculated from the range?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.