Cod sursa(job #935360)

Utilizator rudarelLup Ionut rudarel Data 3 aprilie 2013 08:56:31
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <cstdio>
#define mod 1048575
 
int main()
{
  int ti, ti1,ti2, ti3;
  int n, i;
  freopen("12perm.in", "r", stdin);
  scanf("%d\n", &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;}
 
  ti1=12;
  ti2=6;
  ti3=2;
 
  for(i=5;i<=n;++i)
    {
      ti=ti1+ti3+((i-2)<<1);
    
      ti3=ti2;
      ti2=ti1;
      ti1=ti;
/*    if(ti>mod) ti-=mod;
      if(ti1>mod) ti1-=mod;
      if(ti2>mod) ti2-=mod;
      if(ti3>mod) ti3-=mod;
*/ 
      ti=ti&mod;
      ti1=ti1&mod;
      ti2=ti2&mod;
      ti3=ti3&mod;
    }
  freopen("12perm.out", "w", stdout);
   
  printf("%d\n", ti);
  return 0;
}