#include #include #include #include #include #include #define YES 1 #define NO 0 #define BLANK ' ' #define CR '\n' #define LONG long FILE *fplog; void printbignum(FILE *fpout,char *head,mpz_t mpnum,char c,LONG width); LONG readbignum(mpz_t mpnum,FILE *fpin); char *xmalloc(LONG howmany); int main(int argc,char *argv[]) { LONG i; mpz_t mpp,mpq,mpn; mpz_init(mpp); mpz_init(mpq); mpz_init(mpn); fplog = stdout; for(i = 1; i <= 3; i++) { readbignum(mpp,stdin); printbignum(fplog,"read p: ",mpp,CR,20); mpz_nextprime(mpp,mpp); printbignum(fplog,"prime p: ",mpp,CR,20); readbignum(mpq,stdin); printbignum(fplog,"read q: ",mpq,CR,20); mpz_nextprime(mpq,mpq); printbignum(fplog,"prime q: ",mpq,CR,20); mpz_mul(mpn,mpp,mpq); printbignum(fplog,"product n: ",mpn,CR,20); } // for(i = 1; i <= 3; i++) return(0); } // end main /************************************************************************/ /* */ /* printbignum -- print big num with header and trailing character */ /* */ /************************************************************************/ void printbignum(FILE *fpout,char *head,mpz_t mpnum,char c,LONG width) { char fmtstring[25],*outstring; LONG mpsize; mpsize = mpz_sizeinbase(mpnum,10); outstring = (char *) xmalloc(mpsize + 5); mpz_get_str(outstring,10,mpnum); sprintf(fmtstring,"%%%lds",width); fprintf(fpout,"%s",head); fprintf(fpout,fmtstring,outstring); /* mpz_out_str(fpout,10,mpnum); */ fprintf(fpout,"%c",c); fflush(fpout); free(outstring); } /************************************************************************/ /* */ /* readbignum -- read big num from a file */ /* */ /************************************************************************/ LONG readbignum(mpz_t mpnum,FILE *fpin) { return(mpz_inp_str(mpnum,fpin,10)); } /************************************************************************/ /* */ /* xmalloc */ /* */ /************************************************************************/ char *xmalloc(LONG howmany) { char *thechar; thechar = (char *) malloc(howmany); if(thechar == (char *) 0) { fprintf(fplog,"ERROR malloc fails of %ld\n",howmany); exit(0); } return(thechar); }