# GMP Problem

• 01-01-2005
GMP Problem
I have made a simple program using the GMP library that is the start of a factoring program I'm making. Basically, it just factors a number (n) up to a bound, which is either 4000000000 or the sqrt of the number, whichever is smaller. In this example the number being factored is 1000.
I get three errors, all of which are the same: error C2107: illegal index, indirection not allowed.
I'm pretty sure it has to do with the array but I don't know how to fix it.

Here's the source code, I put a comment before the error lines
Code:

```#include <iostream> #include <gmp.h> using namespace std; int main() {         mpz_t n, k, var, N, N2, array, hold;         mpz_init (n);         mpz_init (k);         mpz_init (hold);         mpz_init (var);         mpz_init (N);         mpz_init (N2);         mpz_set_ui (n, 1000);         mpz_set_ui (k, 2);         mpz_array_init (array, 4000000000, 1);         mpz_sqrt (N, n);         if (mpz_cmp_ui (N, 4000000000) == -1)                 mpz_set_ui (N2, 4000000000);         else                 mpz_set (N2, N);         while (mpz_cmp (k, N2) == -1)         { //the following line has the first two errors                 if (mpz_sgn (array[k]) == 0)                 {                         mpz_cdiv_q (hold, n, k);                         if (mpz_sgn (hold) == 0)                         {                         cout << k << " * " << hold << "; ";                         mpz_set (var, k);                         while (var <= N2)                         {                                 mpz_add (var, var, k); //the following line has the next error                                 mpz_set (array[var], 0);                         }                         }                 }                 mpz_add_ui (k, k, 1);         }         mpz_clear (n);         mpz_clear (k);         mpz_clear (var);         mpz_clear (N);         mpz_clear (N2);         return 0; }```
• 01-01-2005
gcn_zelda
For code tags, you need to use [ and ] instead of < and >
• 01-01-2005
Sebastiani
>> mpz_t n, k, var, N, N2, array, hold;

you declared a single variable, not an array. do you see the problem?
• 01-01-2005
I realize in normal c++ you should do int array[4000000000], but in gmp doesn't the mpz_t_array_init make it an array for you? I fiddled around a bit and fixed the code so that it has no compile errors, but it has link errors now :mad:
Link errors are so annoying...unlike compiler errors you don't get specific lines, and the LNK2001 entry in MSDN encomposes a whole lot of possible problems, compile errors are much more specific about what's going wrong.
Anyways, the error is
error LNK2001: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,struct __mpz_struct const *)" (??6@YAAAV?\$b
asic_ostream@DU?\$char_traits@D@std@@@std@@AAV01@PB U__mpz_struct@@@Z)
I have no idea what that's talking about. :(
The error is for this code:

Code:

```#include <iostream> #include <gmp.h> using namespace std; int main() {         mpz_t n, N, N2, hold;         bool array[100000000];         int k=2, var;         mpz_init (n);         mpz_init (hold);         mpz_init (N);         mpz_init (N2);         mpz_set_ui (n, 1000);         mpz_sqrt (N, n);         if (mpz_cmp_ui (N, 100000000) == -1)                 mpz_set_ui (N2, 100000000);         else                 mpz_set (N2, N);         while (mpz_cmp_ui (N2, k) == 1)         {                 if (array[k] == 1)                 {                         mpz_cdiv_q_ui (hold, n, k);                         if (mpz_sgn (hold) == 0)                         {                         cout << k << " * " << hold << "; ";                         var = k;                         while (mpz_cmp_ui(N2, k) == 1)                         {                                 var = var + k;                                 array[var] = 0;                         }                         }                 }                 k++;         }         mpz_clear (n);         mpz_clear (N);         mpz_clear (N2);         return 0; }```
Is anyone willing to help?
Thanks either way,