\\ product of Eisenstein integers
prd(u,v) = {
	(real(u)*real(v) - imag(u)*imag(v)) + (imag(u)*real(v)+real(u)*imag(v)-imag(u)*imag(v))*I;
}

dz = vector(6)
pw=1
for (k=1, #dz, dz[k]=pw; pw=prd(pw, 1+I));

a(n) = {
	my (d=Vecrev(digits(n,7)), p=1, z=0);
	for (k=1, #d,
		if (d[k],
			z+=prd(dz[d[k]], p);
		);
		p=prd(p, 3+I)
	);
	z
}

{
	for (n=0, 7^logint(100000, 7)-1,
		z=a(n);
		print (n " " real(z));
	);
}

quit