diff options
author | Iru Cai <mytbk920423@gmail.com> | 2018-05-26 16:12:24 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2018-05-26 16:12:24 +0800 |
commit | 1c76beb0d4ccf57d2db84cf417f37a3a155fb905 (patch) | |
tree | 310bbc9bc48b2860f42b9994a62c38a1b91829b8 /euler97.c | |
parent | c98d66aca04d0d839833b6b81bf249822c4ca350 (diff) | |
download | project_euler-1c76beb0d4ccf57d2db84cf417f37a3a155fb905.tar.xz |
58, 76, 97, 104
Diffstat (limited to 'euler97.c')
-rw-r--r-- | euler97.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/euler97.c b/euler97.c new file mode 100644 index 0000000..b0f55bc --- /dev/null +++ b/euler97.c @@ -0,0 +1,30 @@ +#include <openssl/bn.h> + +static const unsigned char _7830457[3] = { 0x77, 0x7b, 0xb9 }; +static const unsigned char _2[1] = {2}; +static const unsigned char _28433[2] = {0x6f, 0x11}; +static const unsigned char _10000000000[5] = {0x02, 0x54, 0x0b, 0xe4, 0x00}; + +int main() +{ + BIGNUM *b28433 = BN_bin2bn(_28433, 2, NULL); + BIGNUM *b2 = BN_bin2bn(_2, 1, NULL); + BIGNUM *b7830457 = BN_bin2bn(_7830457, 3, NULL); + BIGNUM *b10ten = BN_bin2bn(_10000000000, 5, NULL); + + BN_CTX *ctx = BN_CTX_new(); + BIGNUM *r = BN_new(); + BIGNUM *r2 = BN_new(); + BIGNUM *r3 = BN_new(); + BN_mod_exp(r, b2, b7830457, b10ten, ctx); + BN_mul(r2, r, b28433, ctx); + BN_add(r3, r2, BN_value_one()); + BN_mod(r, r3, b10ten, ctx); + + unsigned char res[10]; + int len = BN_bn2mpi(r, res); + for (int i = 0; i < len; i++) + printf("%02x", res[i]); + + puts(""); +} |