实验
include <stdio.h>
include <stdlib.h>
include <string.h>
include <openssl/bn.h>
define MAX_PRIME 1000
int main()
{
BIGNUM *product, *prime;
char *str;
int i;
// 初始化大数库
BN_CTX *ctx = BN_CTX_new();
product = BN_new();
prime = BN_new();
str = BN_bn2dec(product);
BN_set_word(product, 1);
// 计算1000以内素数的乘积
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) {
BN_set_word(prime, i);
BN_mul(product, product, prime, ctx);
}
}
// 输出结果
str = BN_bn2dec(product);
printf("1000以内素数的乘积为: %s\n", str);
// 释放内存
BN_free(prime);
BN_free(product);
BN_CTX_free(ctx);
free(str);
return 0;
}