Pagini recente » Cod sursa (job #452784) | Cod sursa (job #2978436) | Cod sursa (job #3186739) | Cod sursa (job #507780) | Cod sursa (job #1363508)
#include<cstdio>
#include<vector>
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
const int mod = 666013;
const int hmod = 31;
const int DIM = 10005;
char buff[DIM];
int poz;
void read(ll &x)
{
x = 0;
while(buff[poz] < '0' || buff[poz] > '9')
if(++poz == DIM) fread(buff, 1, DIM, stdin), poz = 0;
while(buff[poz] >= '0' && buff[poz] <= '9')
{
x = x * 10 + buff[poz] - '0';
if(++poz == DIM) fread(buff, 1, DIM, stdin), poz = 0;
}
}
vector<pair<ll, int>> H[hmod];
void insert(ll x, int y)
{
int r = x % hmod;
H[r].pb(mp(x, y));
}
int find(ll x)
{
int r = x % hmod;
for(auto it : H[r])
if(it.fi == x)
return it.se;
return 0;
}
int solve(ll x)
{
if(x <= 2) return x;
int ans = find(x);
if(ans) return ans;
if(x & 1) ans = (1LL * solve((x - 1) / 2) * solve((x - 1) / 2)) % mod;
else ans = (2LL * solve(x / 2) * solve((x - 1) / 2)) % mod;
insert(x, ans);
return ans;
}
int main()
{
freopen("ciuperci.in", "r", stdin);
freopen("ciuperci.out", "w", stdout);
ll t;
read(t);
for(; t; t--)
{
ll x;
read(x);
printf("%d\n", solve(x));
for(int i = 0; i < hmod; i++)
H[i].clear();
}
return 0;
}