Cod sursa(job #635418)

Utilizator antoanelaAntoanela Siminiuc antoanela Data 19 noiembrie 2011 11:20:51
Problema Ciuperci Scor 30
Compilator cpp Status done
Runda .com 2011 Marime 0.59 kb
#include <cstdio>
#include <map>
using namespace std;
#define mod 666013
#define ll long long

int q;
ll n;
map <ll, int> m;

ll solve (ll n)
{
	if (n==1) return 1;
	if (n==2) return 2;
	if (m[n]) return m[n];
	n--;
	ll x, y=n/2;
	if (n&1)
	{
		x=solve(y);
		y=solve(y+1);
		x=(2*x*y)%mod;
		m[n+1]=x;
		return x;
	} else
	{
		x=solve(y);
		x=(x*x)%mod;
		m[n+1]=x;
		return x;
	}
}

int main()
{
	freopen("ciuperci.in","r",stdin);
	freopen("ciuperci.out","w",stdout);
	scanf("%d", &q);
	while (q--)
	{
		scanf("%lld", &n);
		printf("%lld\n", solve(n));
	}
}