Cod sursa(job #1851770)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 20 ianuarie 2017 06:12:05
Problema Nunta Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <bits/stdc++.h>
using namespace std;

class big_int{
    static constexpr int baza = 1e9, bufsz = 40;
    array<int, bufsz> *buf;
public:
    big_int(const int x): buf(new array<int, bufsz>{}){ (*buf)[0] = x; }
    big_int(){}
    ~big_int(){ delete buf; }
    void swap(big_int& rhs){
        std::swap(buf, rhs.buf); }
    void operator+=(const big_int& rhs){
        for(int i = 0, carry = 0; i < 40; ++i){
            carry += (*buf)[i] + (*rhs.buf)[i];
            (*buf)[i] = carry % baza;
            carry /= baza; } }
    int size()const{ return bufsz; }
    int operator[](const int x)const{ return (*buf)[x]; } };

ostream& operator<<(ostream& lhs, const big_int& rhs){
    int i = rhs.size()-1;
    while(rhs[i] == 0 && i > 0) --i;
    lhs << rhs[i--];
    for( ; i >= 0; --i){
        lhs << setw(9) << setfill('0') << rhs[i]; }
    return lhs; }

int main(){
    ifstream f("nunta.in");
    ofstream g("nunta.out");
    int n;

    f >> n;

    big_int bigger{1}, smaller{0};
    for( ; n; --n){
        smaller += bigger;
        smaller.swap(bigger); }

    g << bigger << endl;
    return 0; }