Cod sursa(job #1903123)

Utilizator Train1Train1 Train1 Data 4 martie 2017 23:40:24
Problema Algoritmul lui Dijkstra Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.77 kb
#include <fstream>
#include <iostream>
#define mod 100003
using namespace std;
ifstream fin("2sah.in");
ofstream fout("2sah.out");
int n, t, k;
long long putere(long long a, long long b) {
    long long result = 1;
    while (b) {
        if (b&1) {
            result = (result * a) % mod;
        }
        b = b>>1;
        a = (a * a) % mod;
    }
    return result;
}
int main()
{
    fin>>t>>n>>k;
    if (t == 1) {
        k--;
        fout<<putere(3, k);
    } else {
        //k = 2*n + 1 - k;
        int t = n + 1;
        long long a = 0, b = 0, c = 0, d = 1;
        while (k < t) {
            a = b;
            b = c;
            c = d;
            d = (a + b + c) % mod;
            t--;
        }
        fout<<d;
    }
    return 0;
}