Submission

Status:
PPPPPPPPPP

Score: 100

User: Dormon

Problemset: อนุกรม

Language: cpp

Time: 0.003 second

Submitted On: 2025-01-23 14:09:31

#include <iostream>
#include <cstdint>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <numeric>
#include <array>
#include <iomanip> // cout << fixed << setprecision(n);

using namespace std;
const bool TEST_CASE = 0;

template<typename T>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* name, T value) {
    std::cout << name << " : " << value << '\n';
}

template<typename T, typename... Args>
typename std::enable_if<std::is_integral<T>::value>::type
Debug(const char* names, T value, Args... args) {
    const char* comma = strchr(names, ',');
    std::cout.write(names, comma - names) << " : " << value << " | ";
    Debug(comma + 1, args...);
}
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {
    for(auto &x : a) out << x << ' '; 
    return out;
};

#define DORMON
#ifdef DORMON
    #define debug(...) Debug(#__VA_ARGS__, __VA_ARGS__)
#else
    #define debug(...) 
#endif

class BIG_NUM{
private:
    string number;
    int log10;
public:
    BIG_NUM() : number("0"), log10(1) {};
    BIG_NUM(int n){
        string temp = to_string(n);
        reverse(temp.begin(), temp.end());
        number = temp;
        log10 = number.size();
    }
    BIG_NUM(int64_t n){
        string temp = to_string(n);
        reverse(temp.begin(), temp.end());
        number = temp;
        log10 = number.size();
    }
    BIG_NUM(string s) : number(s), log10((int)s.size()) {};
    BIG_NUM operator+(const BIG_NUM &o) const {
        string res = "";
        int t = 0, n = log10, m = o.log10;
        for (int i = 0;i < max(n, m);i++){
            int k = t;
            if (i < n)
                k += number[i] - '0';
            if (i < m)
                k += o[i] - '0';
            res += (k%10) + '0';
            t = k/10;
        }
        if (t)
            res += '1';
        return BIG_NUM(res);
    }
    friend ostream& operator<<(ostream &out, BIG_NUM &o){
        string tmp = o.number;
        reverse(tmp.begin(), tmp.end());
        out << tmp;
        return out;
    }
    char operator[](size_t i) const {
        return this->number[i];
    }
};

using big = BIG_NUM;

void solve(){
    int n;
    cin >> n;
    vector<big> dp(n+1);
    dp[0] = big(0);
    dp[1] = big(1);
    for (int i = 2;i <= n;i++)
        dp[i] = dp[i-1] + dp[i-2];
    cout << dp[n] << '\n';
}


int main()
{
    #ifndef DORMON
        ios_base::sync_with_stdio(false); 
    #endif
    cin.tie(0);
    int q = 1; 
    if (TEST_CASE) cin >> q;
    while (q--){
        solve();
    }
}