Cod sursa(job #2023780)

Utilizator cella.florescuCella Florescu cella.florescu Data 19 septembrie 2017 14:33:13
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <bits/stdc++.h>

using namespace std;

const int BASE = 10;

struct Huge {
  int numcif;
  int v[1000];
  Huge () {
    numcif = 0;
    memset(v, 0, sizeof v);
  }
  Huge operator + (const Huge &other) const {
    Huge aux;
    int i, t = 0;
    for (i = 1; i <= numcif || t; ++i, t /= BASE)
      aux.v[i] = (t += v[i] + other.v[i]) % BASE;
    aux.numcif = i - 1;
    return aux;
  }
} q[4];

int main()
{
    int n, ind;
    ifstream fin("nunta.in");
    fin >> n;
    fin.close();
    q[0].numcif = q[1].numcif = q[0].v[1] = q[1].v[1] = ind = 1;
    for (int i = 1; i < n; ++i) {
      ind = ((ind + 1) & 3);
      q[ind] = q[(ind + 3) & 3] + q[(ind + 2) & 3];
    }
    ofstream fout("nunta.out");
    for (int i = q[ind].numcif; i > 0; --i)
      fout << q[ind].v[i];
    fout.close();
    return 0;
}