Pagini recente » Cod sursa (job #1637072) | Cod sursa (job #153013) | Cod sursa (job #1829896) | Cod sursa (job #1520541) | Cod sursa (job #637500)
Cod sursa(job #637500)
#include <cstdio>
#include <fstream>
using namespace std;
const int MOD = 666013;
int Q;
long long N;
long long power(int x, int y)
{
if (y == 0) return 1;
if (y % 2 == 0) return power((1LL * x * x) % MOD, y / 2);
return (1LL * x * power((1LL * x * x) % MOD, y / 2)) % MOD;
}
int main()
{
ifstream fin("ciuperci.in");
ofstream fout("ciuperci.out");
fin >> Q;
while (Q--)
{
fin >> N;
long long aux = 1;
while (N >= aux)
N -= aux, aux *= 2;
long long result = 1, runda = aux, num1 = N, num2 = 0, exp1 = 1, exp2 = 0;
if (N % 2 == 1)
num2 = num1, exp1 = 0, exp2 = 1;
while (runda != 1)
{
num1 /= 2, exp1 *= 2;
result *= (exp2 != 0 ? power(2, exp2) : 1);
if (result >= MOD) result -= MOD;
exp1 += exp2;
num2 /= 2, ++num2;
if (num1 % 2 == 1)
{
swap(num1, num2);
swap(exp1, exp2);
}
runda /= 2;
}
fout << result << '\n';
}
fin.close();
fout.close();
}