Cod sursa(job #2025322)

Utilizator cella.florescuCella Florescu cella.florescu Data 22 septembrie 2017 16:11:27
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <cstdio>

using namespace std;

const int BASE = 10;
const int DIG = 211;

unsigned char a[DIG], b[DIG];

int main()
{
    int n, j, x;
    fscanf(fopen("nunta.in", "r"), "%d", &n);
    a[0] = a[1] = b[0] = b[1] = 1;
    for (int i = 1; i < n; ++i) {
      int t = 0;
      for (j = 1; j <= b[0] || t; ++j, t /= BASE) {
        x = b[j];
        b[j] = (t += a[j] + b[j]) % BASE;
        a[j] = x;
      }
      a[0] = b[0];
      b[0] = j - 1;
    }
    FILE *fout = fopen("nunta.out", "w");
    for (int i = b[0]; i > 0; --i)
      fprintf(fout, "%d", b[i]);
    return 0;
}