Prolem with Integer Division

jack THE RED jack_the_red at
Sat Feb 6 15:29:28 CET 2010

Hi everyone!
I'm new to GMP and I have a problem regarding the integer division.
I did read the manual and tried a lot of the division function.

But the result is always something weird:
"so 1234 = 2 x 3218735876"
Can someone tell me what is the problem?


#include <stdio.h> 
#include <gmp.h>

int main(){ 
    mpz_t n; 
    mpz_t root;
    mpz_t remainder;
    mpz_t s;
    mpz_init (n);
    mpz_init (root);
    mpz_init (remainder);
    mpz_init (s);
    printf("Please enter a number to by two: \n"); 
    gmp_scanf ("%Zd",&n); 

    gmp_printf("number inputed %Zd  \n", n);
    gmp_printf("number root %Zd  \n", root);
    mpz_mod_ui(remainder,s,2);//remainder <- n%2
    if (mpz_cmp_ui(remainder,1)){// if remainder!=1 (means that n is an even number)
        gmp_printf("This is an even number, so %Zd = 2 x ", n);
        mpz_div_ui(n, n, 2); /// Error here! 
        gmp_printf("%lu \n", n);
    mpz_clear (n);
    mpz_clear (root);
    mpz_clear (remainder);
    mpz_clear (s); 
    return 0; 
Hotmail: Powerful Free email with security by Microsoft.

More information about the gmp-discuss mailing list