Cod sursa(job #2025316)

Utilizator cella.florescuCella Florescu cella.florescu Data 22 septembrie 2017 15:56:39
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <cstdio>
#include <cstring>
using namespace std;
const int BASE = 10;
const int DIG = 211;
unsigned char a[DIG], b[DIG], c[DIG];
int main()
{
    int n, j;
    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] || j <= a[0] || t; ++j, t /= BASE)
        c[j] = (t += a[j] + b[j]) % BASE;
      c[0] = j - 1;
      memcpy(a, b, sizeof b);
      memcpy(b, c, sizeof c);
    }
    FILE *fout = fopen("nunta.out", "w");
    for (int i = c[0]; i > 0; --i)
      fprintf(fout, "%d", c[i]);
    return 0;
}