Cod sursa(job #778357)

Utilizator visanrVisan Radu visanr Data 14 august 2012 15:57:30
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define MOD 1048575
int x1, x2, x3, x4, x5, n;

int main()
{
    freopen("12perm.in", "r", stdin);
    freopen("12perm.out", "w", stdout);
    int i;
    scanf("%i", &n);
    x1 = 1, x2 = 2, x3 = 6, x4 = 12;
    switch(n)
    {
             case 1:
                  {
                       printf("1\n");
                       return 0;
                  }
             case 2:
                  {
                       printf("2\n");
                       return 0;
                  }
             case 3:
                  {
                       printf("6\n");
                       return 0;
                  }
             case 4:
                  {
                       printf("12\n");
                       return 0;
                  }
    }
    for(i = 5; i <= n; i++)
    {
          x5 = (x4 + x2 + (i - 2) * 2) & MOD;
          x2 = x3;
          x3 = x4;
          x4 = x5;
    }
    printf("%i\n", x4);
    return 0;
}