Cod sursa(job #865261)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 26 ianuarie 2013 12:07:50
Problema Al k-lea termen Fibonacci Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.37 kb
#include <cstdio>
using namespace std;

#define modulo 666013

int main(){

    freopen("kfib.in", "r", stdin);
    freopen("kfib.out", "w", stdout);

    int k;
    int a, b, c;

    scanf("%d", &k);

    k %= modulo * 2 + 2;
    a = b = 1;

    for(int i = 3; i <= k; i++)
        c = (a + b) % modulo,
        a = b,
        b = c;

    printf("%d", b);

    return 0;
}