Pagini recente » Cod sursa (job #2460436) | Cod sursa (job #451371) | Cod sursa (job #1956071) | Cod sursa (job #658950) | Cod sursa (job #1104611)
#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>
using namespace std;
const char infile[] = "ciuperci.in";
const char outfile[] = "ciuperci.out";
ifstream fin(infile);
ofstream fout(outfile);
const int MAXN = 100005;
const int MOD = 666013;
const int U = 31;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
int T;
long long N;
vector <pair<long long, int> > Hash[U];
inline int SearchHash(const long long & x) {
int Key = (x % U);
for(vector <pair<long long, int> > :: iterator it = Hash[Key].begin(), fin = Hash[Key].end() ; it != fin ; ++ it)
if(it->first == x)
return it->second;
return -1;
}
inline void AddHash(const pair<long long, int> & x) {
int Key = N % U;
for(vector <pair<long long, int> > :: iterator it = Hash[Key].begin(), fin = Hash[Key].end(); it != fin ; ++ it)
if(it->first == x.first) {
it->second += x.second;
return;
}
Hash[Key].push_back(x);
}
int Solve(const long long &x) {
if(x <= 2)
return x;
int val = SearchHash(x);
if(val != -1)
return val;
if(x & 1) {
val = Solve((x - 1) >> 1);
val = (1LL * val * val) % MOD;
}
else
val = (1LL * 2 * Solve((x - 1) >> 1) * Solve(((x - 1) >> 1) + 1)) % MOD;
AddHash(make_pair(x, val));
return val;
}
int main() {
fin >> T;
while(T --) {
fin >> N;
fout << Solve(N) << '\n';
for(int i = 0 ; i < U ; ++ i)
vector< pair<long long, int> > ().swap(Hash[i]);
}
fin.close();
fout.close();
return 0;
}