nimsum = bitxor

\\ after https://www.math.ucla.edu/~tom/NimProd.txt
nimprod(x, y) = {
	my (F, i, t);

    if (x>y, [x,y]=[y,x]);              \\ Now x<=y

    if (x==0, return (0),               \\ Now x>=1
        x==1, return (y),               \\ Now x>=2
        y==2, return (3),               \\ Now y>=3
        y==3, return (if (x==2, 1, 2))	\\ Now y>=4
	);

    F=4;   \\ Fermat 2-power

    while (1,
        if (y==F, return (if (x<y, x*y, 3*y/2)),
           y<2*F, return (nimsum(nimprod(F,x), nimprod(y-F,x)))
		);

	    t=2*F;
	    while (t<F*F,
			if (y==t,
				if (x<F, return (nimprod(nimprod(x,t/F),F)));

				i=F;
				while (i<t,
					if (x==i,  return (nimprod(nimprod(F,F), nimprod(t/F,i/F))),
					    x<2*i, return (nimsum(nimprod(t,i), nimprod(t,x-i))));

					i*=2;
				);

             	if (x==t, return (nimprod(nimprod(F,F),nimprod(t/F,t/F))));
          	);

		  	if (y<2*t, return (nimsum(nimprod(t,x), nimprod(y-t,x))));

	   		t*=2;
        );

        F=F*F;
    );
}

for (n=0, 1000, print (n " " nimprod(2^4, 2^n)))

quit