/* http://projecteuler.net/
 *
 * Problem 65
 * Find the sum of digits in the numerator of the 100th convergent of the
 * continued fraction for e.
 *
 * Solution by Melkor (Filip Niksic, fniksic@gmail.com)
 *
 **/

#include <iostream>

#include "related/bignum.h"

using namespace std;

int main() {
    BigNum p(1), pp(0);

    for (int i = 0; i < 100; ++i) {
	BigNum tmp_p(p);
	if (i == 0)
	    p.mul(2);
	else if (i % 3 == 2)
	    p.mul(2*(i+1)/3);
	else
	    ;
	p += pp;
	pp = tmp_p;
    }

    cout << p.sum_digits10() << endl;
    return 0;
}

