Cod sursa(job #639378)

Utilizator Teodor94Teodor Plop Teodor94 Data 23 noiembrie 2011 09:16:54
Problema Ciuperci Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<cstdio>

const int MOD = 666013;

long long arbore(int x) {
    if (x == 1)
        return 1;

    if (x == 2)
        return 2;

    if (x % 2 == 1) {
        long long rez = arbore(x / 2);
        return rez * rez % MOD;
    }

    return arbore(x / 2 - 1) * arbore(x / 2) % MOD * 2 % MOD;
}

void rez() {
    int t;
    scanf("%d", &t);

    for (int i = 1; i <= t; ++i) {
        int n;
        scanf("%d", &n);
        printf("%lld\n", arbore(n));
    }
}

int main() {
    freopen("ciuperci.in", "r", stdin);
    freopen("ciuperci.out", "w", stdout);

    rez();

    return 0;
}