Cod sursa(job #2666561)

Utilizator motrocgabiMotroc Gabriel motrocgabi Data 2 noiembrie 2020 09:56:38
Problema Al k-lea termen Fibonacci Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
// Al k-lea termen Fibonacci.cpp : This file contains the 'main' function. Program execution begins and ends there.
//https://www.infoarena.ro/problema/kfib

#include <iostream>
#include <fstream>

using namespace std;

int mem[666013];

int fib(int n)
{
    int answer;
    if (mem[n])
        return mem[n];
    if (n == 1 || n == 2)
        answer = 1;
    else
    {
        answer = fib(n - 1) + fib(n - 2);
        mem[n] = answer;
    }
    return answer;
}

int main()
{
    int a;
    ifstream f("kfib.in");
    f >> a;
    a = a % 666013;
    ofstream g("kfib.out");
    g << fib(a);
    f.close();
    g.close();
}