Cod sursa(job #2768437)

Utilizator DragosC1Dragos DragosC1 Data 10 august 2021 18:37:47
Problema Nunta Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <fstream>
using namespace std;

int n;

typedef int BigNr[1001];

void read() {
    ifstream f("nunta.in");
    f >> n;
    f.close();
}

BigNr fib[1001];
int lung[1001];

void solve() {
    int i, j, t;
    fib[1][++lung[1]] = 1;
    fib[2][++lung[2]] = 2;
    for (i = 3; i <= n; i++) {
        t = 0;
        lung[i] = max(lung[i - 1], lung[i - 2]);
        for (j = 1; j <= lung[i]; j++) {
            t = t + fib[i - 1][j] + fib[i - 2][j];
            fib[i][j] = t % 10;
            t /= 10;
        }
        while (t) {
            fib[i][++lung[i]] = t % 10;
            t /= 10;
        }
    }
}

void output() {
    int i;
    ofstream g("nunta.out");
    for (i = lung[n]; i >= 1; i--)
        g << fib[n][i];
    g.close();
}

int main() {
    read();
    solve();
    output();
    return 0;
}