Pagini recente » preoni2007_runda2_10 | Cod sursa (job #854798) | Cod sursa (job #2904232) | Cod sursa (job #1276445) | Cod sursa (job #1293987)
#include <fstream>
#include <vector>
using namespace std;
ifstream in("ciuperci.in");
ofstream out("ciuperci.out");
struct ciuperca{
int x, y;
};
const int mod= 666013, auxmod = 63;
int q;
vector <ciuperca> v[auxmod];
int query(long long x)
{
if(x<3)
return x;
int rest = x % auxmod, chestie;
for(int i = 0; i<(int)v[rest].size(); i++)
{
if(v[rest][i].x==x)
return v[rest][i].y;
}
if(x%2==1)
{
chestie = (long long)query(x / 2) * query(x / 2) % mod;
}
else
{
chestie = (long long)query(x / 2) * query(x / 2 - 1) * 2 % mod;
}
ciuperca aux;
aux.x = x;
aux.y = chestie;
v[rest].push_back(aux);
return chestie;
}
int main(){
int player_unu=0;
in>>q;
for (int shp = 0; shp<q; shp++)
{
long long x;
in>>x;
for(int i = 0; i<auxmod; i++)
v[i].clear();
out<<query(x)<<"\n";
}
return player_unu;
}