Cod sursa(job #636243)

Utilizator MinionMinionul nr. 4 Minion Data 19 noiembrie 2011 18:04:22
Problema Ciuperci Scor 50
Compilator cpp Status done
Runda .com 2011 Marime 0.75 kb
#include <cstdio>

typedef long long i64;

i64 v[75001];

inline i64 fct(i64 x)
{
    if (x<75001)
        return v[x];
    else if (x&(x-1)==0)
        return 1;
    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<75001;++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;
}