include <stdio.h>
include <stdlib.h>
include <gmp.h>
define MAX_PRIME 10000
int main()
{
mpz_t prime, n;
int i;
// 初始化大数库
mpz_init(prime);
mpz_init(n);
mpz_set_ui(prime, 2);
// 计算10000以内素数
for (i=2; i<=MAX_PRIME; i++) {
int is_prime = 1;
int j;
for (j=2; j*j<=i; j++) {
if (i % j == 0) {
is_prime = 0;
break;
}
}
if (is_prime) {
mpz_set_ui(n, i);
mpz_mul(prime, prime, n);
}
}
// 输出结果
gmp_printf("10000以内素数的乘积为: %Zd\n", prime);
// 释放内存
mpz_clear(n);
mpz_clear(prime);
return 0;
}
标签:prime,10000,int,init,实验,include,mpz From: https://www.cnblogs.com/saberwc/p/17386947.html