Cod sursa(job #46570)

Utilizator damaDamaschin Mihai dama Data 2 aprilie 2007 19:09:14
Problema 12-Perm Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define modul 1 << 20


int main()
{
    freopen("12perm.in","r",stdin);
    freopen("12perm.out","w",stdout);

    int one, two, three, n, i, temp;

    one = 2;
    two = 6;
    three = 12;

    scanf("%d", &n);

    if(n == 1)
    {
        printf("1\n");
        return 0;
    }
    if(n == 2)
    {
            printf("2\n");
            return 0;
    }
    if(n == 3)
    {
        printf("6\n");
        return 0;
    }
    if(n == 4)
    {
        printf("12\n");
        return 0;
    }

    for(i = 5; i <= n; ++i)
    {
        temp = (one + three + 2 * i - 4);
        temp %= modul;
        one = two;
        two = three;
        three = temp;
    }

    printf("%d\n", three);


    return 0;
}