Cod sursa(job #175671)

Utilizator Mishu91Andrei Misarca Mishu91 Data 10 aprilie 2008 11:54:13
Problema 12-Perm Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <cstdio>
#define MOD 1048576

long n;

int T[15000003];

int main()
{
  freopen("12perm.in","r",stdin);
  freopen("12perm.out","w",stdout);
  scanf("%ld\n",&n);
  
  T[1] = 1;
  T[2] = 2;
  T[3] = 6;
  T[4] = 12;
  
  for(int i=5; i<=n; i++)
    T[i] = ((T[i - 1] + T[i - 3] + 2 * (i - 2) ) > MOD) ? (T[i - 1] + T[i - 3] + 2 * (i - 2) ) - MOD : (T[i - 1] + T[i - 3] + 2 * (i - 2)); 
    
  printf("%d\n",T[n]);
  return 0;
}