Cod sursa(job #636220)

Utilizator MinionMinionul nr. 4 Minion Data 19 noiembrie 2011 17:49:07
Problema Ciuperci Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 0.71 kb
#include <cstdio>

typedef long long i64;

int v[200001];

inline i64 fct(i64 x)
{
    if (x<200001)
        return v[x];
    else if (x&1)
    {
        i64 aux=fct(x>>1);
        return (aux*aux)%666013;
    }
    else
        return (2*fct(x>>1)*fct((x>>1)-1))%666013;

}

int main()
{
    int t,i;
    long long n;
    freopen("ciuperci.in","r",stdin);
    freopen("ciuperci.out","w",stdout);
    scanf("%d",&t);
    for (v[0]=1,v[1]=1,i=2;i<200001;++i)
        if (i&1)
            v[i]=(v[i>>1]*v[i>>1])%666013;
        else
            v[i]=(2*v[(i>>1)-1]*v[i>>1])%666013;
    for (;t;--t)
    {
        scanf("%lld",&n);
        printf("%lld\n",fct(n));
    }
    return 0;
}