s = 0
unseen = 1
seen(v) = bit test(s, v)
see(v) = s = bit or(s, 2^v); while (seen(unseen), unseen++)

a = vector(M=1000);
u = 1;

find(m) = {
	fordiv (m, d,
		if (d>M^2,
				return (oo),
			!seen(d),
				see(d);
				return (d)
		);
	);
}

{

	for (n=1, oo,
		v = find(n*(n+1)/2);
		if (v!=oo && issquare(v),
			a[sqrtint(v)] = n;
			while (a[u],
				print (u " " a[u]);
				if (u++ > #a,
					break (2);
				);
			);
		);
	);
}

quit