GMPライブラリを使えば簡単に多倍長演算ができます.
- インストール:
sudo apt-get install libgmp3-dev
- コンパイル:
gcc -lgmp example.c
c
1#include <stdio.h>
2#include <gmp.h>
3
4int main(void)
5{
6 mpz_t a, b, c;
7 unsigned long long i = 0ULL;
8
9 mpz_init(a); mpz_init(b); mpz_init(c);
10 mpz_set_ui(a, 1UL); mpz_set_ui(b, 1UL);
11
12 printf("%010llu: ", ++i); mpz_out_str(stdout, 10, a); printf("\n");
13 printf("%010llu: ", ++i); mpz_out_str(stdout, 10, b); printf("\n");
14
15 while (1) {
16 mpz_add(c, a, b);
17 mpz_set(a, b);
18 mpz_set(b, c);
19 printf("%010llu: ", ++i); mpz_out_str(stdout, 10, c); printf("\n");
20 }
21
22 mpz_clear(a); mpz_clear(b); mpz_clear(c);
23 return 0;
24}
【1〜】
【400〜】
【800〜】
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/04/20 15:03