Cod sursa(job #635637)

Utilizator ProtomanAndrei Purice Protoman Data 19 noiembrie 2011 13:44:50
Problema Ciuperci Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 1.08 kb
#include <algorithm>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <set>
#include <unordered_map>

#define restRez 666013
#define ll long long

#define pb push_back

using namespace std;

int main()
{
	ifstream cin("ciuperci.in");
	ofstream cout("ciuperci.out");

	int testCases;
	for (cin >> testCases; testCases; testCases--)
	{
		ll n;
		cin >> n;

		vector <ll> vctCalc;
		vctCalc.pb(n);
		for (int i = 0; i < vctCalc.size(); i++)
		{
			ll x = vctCalc[i];

			x--;
			if (x - x / 2 && x - x / 2 < vctCalc[vctCalc.size() - 1])
				vctCalc.pb(x - x / 2);
			if (x / 2 && x / 2 < vctCalc[vctCalc.size() - 1])
				vctCalc.pb(x / 2);
		}

		reverse(vctCalc.begin(), vctCalc.end());

		unordered_map <ll, ll> sol;
		sol[1] = 1;
		sol[0] = 1;
		for (int i = 0; i < vctCalc.size(); i++)
		{
			ll x = vctCalc[i];
			x--;

			ll s1 = sol[x / 2], s2 = sol[x - (x / 2)];

			if (x & 1)
				sol[x + 1] = 2 * s1 * s2 % restRez;
			else sol[x + 1] = s1 * s2 % restRez;
		}

		cout << sol[n] << '\n';
	}

	return 0;
}