Cod sursa(job #988619)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 23 august 2013 14:39:50
Problema Sortari2 Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>

using namespace std;

#define modulo 999017

int factorial( int n )
{
    int s = 1;

    for ( int i = 2; i <= n; ++i )
            s = ( s * i ) % modulo;

    return s;
}

int Fibonacci( int n )
{
    int a = 0;
    int b = 1;
    int c = 1;

    for ( int i = 3; i <= n; ++i )
    {
        c = ( a + b ) % modulo;
        a = b;
        b = c;
    }

    return c;
}

int N;

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

    f >> N;

    g << ( factorial( N ) - Fibonacci( 2 * N ) + modulo ) % modulo << "\n";

    f.close();
    g.close();

    return 0;
}