C++競プロ学習日記(仮)

( 学習記録であり解説Blogではないです )

C++で多倍長整数!

C++多倍長整数が使える事をコンテスト中に知ったのでメモ。
でも標準ライブラリではなく、boost (オープンソースライブラリ) を使う様です。

参考)Chapter 1. Boost.Multiprecision - 1.53.0
参考)多倍長整数 - boostjp

cpp_int はメモリが許す限り無限の桁数を扱える型。

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp> // <-- add!!!
using namespace std;
using namespace boost::multiprecision; // <-- add!!!
cpp_int sum( cpp_int N )
{
	if( N == 0 ) return 1;
	else return N * sum( N - 1 );
}
int main()
{
    int N;
    cin >> N;
    
    cout << sum( N ) << endl;
}

実行コード:[Wandbox]三へ( へ՞ਊ ՞)へ ハッハッ

1000! もちゃんと全桁出力できる(感動)

( AtCoderでは boost バージョン: 1.60.0 が使える! *1 )