Cod sursa(job #906446)
| Utilizator | Data | 6 martie 2013 20:36:34 | |
|---|---|---|---|
| Problema | 12-Perm | Scor | 90 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.59 kb |
#include<cstdio>
#include<queue>
using namespace std;
queue <int> q;
int solve (int x)
{
int rez,i;
if (x==1)
return 1;
if (x==2)
return 2;
if (x==3)
return 6;
if (x==4)
return 12;
q.push(2);
q.push(6);
q.push(12);
for (i=5; i<=x; i++)
{
rez=q.back()+q.front()+2*(i-2);
rez&=(1<<20)-1;
q.push(rez);
q.pop();
}
return q.back();
}
int main ()
{
int n;
freopen("12perm.in","r",stdin);
freopen("12perm.out","w",stdout);
scanf("%d",&n);
printf("%d\n",solve(n));
return 0;
}
