Cod sursa(job #1363518)

Utilizator mirceadinoMircea Popoveniuc mirceadino Data 27 februarie 2015 00:27:18
Problema Ciuperci Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.67 kb
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "ciuperci";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif

typedef long long int lld;
typedef pair<int, int> PII;
typedef pair<int, lld> PIL;
typedef pair<lld, int> PLI;
typedef pair<lld, lld> PLL;

const int INF = (1LL << 31) - 1;
const lld LINF = (1LL << 62) - 1;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
const int MOD = 666013;

const int NMAX = 100000 + 5;
const int MMAX = 100000 + 5;
const int KMAX = 100000 + 5;
const int PMAX = 100000 + 5;
const int LMAX = 100000 + 5;
const int VMAX = 100000 + 5;

int Q;
lld N;

int solve(lld full, lld n) {
    if(n == 1)
        return full % MOD;

    if(n == full)
        return 1;

    return ((1 + n % 2) * solve(full / 2, n / 2) * 1LL * solve(full / 2, n - n / 2)) % MOD;
}

int main() {
    lld p, a, b;

#ifndef ONLINE_JUDGE
    freopen(inputFile.c_str(), "r", stdin);
    freopen(outputFile.c_str(), "w", stdout);
#endif

    scanf("%d", &Q);

    while(Q--) {
        scanf("%lld", &N);
        p = log2(N + 0.5);
        a = (1LL << p);
        b = N - a + 1;
        printf("%d\n", solve(a, b));
    }

    return 0;
}