I have this code which previously used the BigInteger library, however now I have GMP installed and I want to use that instead.

I have read the manual but I cannot figure out how to use GMP in this function without getting errors.

Here is the function:
Code:
int lucas(long p){ //p is a number in the range of 2 up to 50,000,000, possibly bigger
	int s = 4; //previously assigned as a big integer
	int z; //used in the for loop below
	int M = 2; //previously assigned as a big integer
	for(z = 1; z < p; z++){ //this accomplishes the same as 2 to the power of p, and is stored in M
		M *= 2;
	}
	M--; 
	int i; //used for the loop below
	for(i = 3; i <= p; i++){
		s = ((s * s) - 2) % M; //this where the bulk of the work happens
	}
		if(s == 0){ 
			return(2); //if s is 0, 2^p - 1 is prime
		}
		else
		{
			return(1); //if anything else it isn't
		}
}
I can initialize variables using the gmp library, but when I'm trying to use the mpz_pow_ui() function I get errors because it wants me to use long integers, which are too small for the numbers I want to work with.

How can I re-write this function to use GMP?

Thank You