Pagini recente » Cod sursa (job #1426239) | Cod sursa (job #2923601) | Cod sursa (job #1359653) | Cod sursa (job #1759385) | Cod sursa (job #614061)
Cod sursa(job #614061)
Utilizator |
Mr. Noname cezar305 |
Data |
5 octombrie 2011 15:57:49 |
Problema |
Ciuperci |
Scor |
Ascuns |
Compilator |
cpp |
Status |
done |
Runda |
|
Marime |
0.66 kb |
#include <stdio.h>
#define MAXN 20000
#define MOD 666013
int D[MAXN];
int T;
int i;
long long x;
int mem(long long x)
{
if (x < MAXN) return D[x];
int aux = mem(x/2);
if (x % 2 == 1)
return ((1LL * aux * aux) % MOD);
else
return ( (1LL * 2 * aux * mem(x/2 - 1) ) % MOD);
}
int main()
{
freopen("ciuperci.in","r",stdin);
freopen("ciuperci.out","w",stdout);
scanf("%d",&T);
D[0] = D[1] = 1;
for (i=2; i<MAXN; ++i)
if (i % 2 == 1)
D[i] = (1LL * D[i/2] * D[i/2]) % MOD;
else
D[i] = (1LL * 2 * D[i/2] * D[i/2 - 1] ) % MOD;
for (i=1; i<=T; ++i){
scanf("%lld\n",&x);
printf("%d\n", mem(x));
}
return 0;
}