111
将gmp安装到学号目录下:
在ubuntu下实现:
代码:
#include<gmp.h> int main() { mpz_t a,c, b[11], c1[11], d; mpz_init(a); mpz_init(c); mpz_init(d); mpz_init_set_str(d, "1", 10); mpz_init_set_ui(a, 2); mpz_pow_ui(c, a, 1217); gmp_printf("c = %Zd\n", c); const char s[11][9]={"20181212","20181213","20181214","20181215","20181216","20181217","20181218","20181219","20181220","20181221","20181222"}; int i; for(i=0;i<11;i++) { mpz_init(b[i]); mpz_init_set_str(b[i],s[i], 10); mpz_mul(d, d, b[i]); } gmp_printf("d = %Zd\n", d); for(i=0;i<11;i++){ mpz_clear(b[i]); } mpz_clear(a); mpz_clear(c); mpz_clear(d); return 0; }
编译及运行结果:(调用gmp大数库时,要附上头文件以及lib库的位置)
与bc对比一下:
可知,代码是很正确的~~