proj euler 1 in constant time