Cod sursa(job #552933)

Utilizator nandoLicker Nandor nando Data 13 martie 2011 10:48:51
Problema Nunta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

fstream fin ("nunta.in", ios::in);
fstream fout ("nunta.out", ios::out);


#define max(a,b) (((a) > (b)) ? (a) : (b))
#define BASE 10
typedef int Huge[300];

Huge a, b;

int main ()
{
    int n;
    fin >> n;

    a[0] = b[0] = a[1] = b[1] = 1;

    for (int i = 1; i < n; ++i) {
        int t = 0, c;
        a[0] = b[0];
        for (int j = 1; j <= b[0]; ++j) {
            c = (a[j] + b[j] + t) % BASE;
            t = (a[j] + b[j] + t) / BASE;

            a[j] = b[j], b[j] = c;
        }

        if (t) {
            b[++b[0]] = t;
        }
    }


    for (int i = b[0]; i; --i) {
        fout << b[i];
    }
    fout << endl;

    fin.close ();
    fout.close ();
    return 0;
}