Cod sursa(job #2023787)

Utilizator cella.florescuCella Florescu cella.florescu Data 19 septembrie 2017 14:47:19
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
#include <iomanip>

using namespace std;

const int BASE = 1e9;
const int DIG = 20;

struct Huge {
  int numcif;
  int v[DIG];
  Huge () {
    numcif = 0;
    for (int i = 0; i < DIG; ++i)
      v[i] = 0;
  }
  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;
  }
} a, b, c;

int main()
{
    int n, ind;
    ifstream fin("nunta.in");
    fin >> n;
    fin.close();
    a.numcif = a.v[1] = ind = 1;
    b = c = a;
    for (int i = 1; i < n; ++i) {
      c = a + b;
      a = b; b = c;
    }
    ofstream fout("nunta.out");
    for (int i = c.numcif; i > 0; --i)
      fout << c.v[i] << setfill('0') << setw(9);
    fout.close();
    return 0;
}