#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <gmp.h>
#include <time.h>
/*#include "mpi.h"*/
int main (int argc, char *argv[]){
    clock_t start, end;
    double elapsed;
    start = clock();
    mpz_t     N;
    mpz_t     B,A,test,two,Q;
    mpz_init(N);
    mpz_init_set_str (N, argv[1], 10);   /* 2533965587 136868736177707213657 951481467360591658636268654185633689926419097 */
    mpz_init(A);
    mpz_init(B);
    mpz_init(Q);
    mpz_init(test);
    mpz_init(two);
    mpz_init_set_str(two,"2",10);
    mpz_tdiv_qr(Q,test,N,two);  
    if (mpz_cmp_ui(test,0) == 0) {
        end = clock();
        elapsed=((double) (end - start)) / CLOCKS_PER_SEC;
        mpz_out_str (stdout, 10, N);
        printf("=2 * ");
        mpz_out_str (stdout, 10, Q);
        printf("\nelapsed time = ");
        printf(" %f seconds \n", elapsed);
        return 0;
    }
    mpz_init_set_str(B,"3",10);
    mpz_sqrt(A,N);
    while ( mpz_cmp(A,B) >= 0) {
        mpz_tdiv_qr(Q,test,N,B);  
        if (mpz_cmp_ui(test,0) == 0) {
            end = clock();
            elapsed=((double) (end - start)) / CLOCKS_PER_SEC;
            mpz_out_str (stdout, 10, N);
            printf("=  ");
            mpz_out_str (stdout, 10, Q);
            printf(" * ");
            mpz_out_str (stdout, 10, B);
            printf("   \n");
            printf("elapsed time = ");
            printf(" %f seconds  \n", elapsed);
            return 0;
        }
        mpz_add_ui(B,B,2);
    }
    mpz_out_str (stdout, 10, N);
    printf(" is a prime. \n");
    end = clock();
    elapsed=((double) (end - start)) / CLOCKS_PER_SEC;
    printf("elapsed time = ");
    printf(" %f seconds  \n", elapsed);
    return 0;;
}