Cod sursa(job #637403)

Utilizator cosmyoPaunel Cosmin cosmyo Data 20 noiembrie 2011 14:17:02
Problema Ciuperci Scor 30
Compilator cpp Status done
Runda .com 2011 Marime 0.66 kb
#include <fstream>
using namespace std;
const long long MOD = 666013;
int MODULO[100005];
int ARBORE(long long N){
	if(N == 2)
		return 1;
	if(N == 1)
		return 0;
	if(N % 2 == 1){
		int x = ARBORE((N-1) / 2);
		return x + x;
	}
	else{
		int x = ARBORE(N / 2);
		int y = ARBORE((N - 1) / 2);
		return x + y + 1;
	}
}

int main() {
	ifstream fin("ciuperci.in");
	ofstream fout("ciuperci.out");
	int Q, N;
	fin >> Q;
	for(; Q; --Q){
		fin >> N;
		int power = ARBORE(N);
		long long rez = 1, a = 2;
		for(int i = 0; (1 << i) <= power; ++i){
			if(power & (1 << i))
				rez = ((long long)rez * a) % MOD;
			a = ((long long)a * a) % MOD;
		}

		fout << rez << '\n';

	}

	return 0;
}