A positive integer k
is a Loeschian number if
k
can be expressed asi*i + j*j + i*j
fori
,j
integers.
For example, the first positive Loeschian numbers are: 1
(i=1
, j=0
); 3
(i=j=1
); 4
(i=2
, j=0
); 7
(i=2
, j=1
); 9
(i=-3
, j=3
); ... Note that i
, j
for a given k
are not unique. For example, 9
can also be generated with i=3
, j=0
.
Other equivalent characterizations of these numbers are:
k
can be expressed asi*i + j*j + i*j
fori
,j
non-negative integers. (For each pair of integersi
,j
there's a pair of non-negative integers that gives the samek
)There is a set of
k
contiguous hexagons that forms a tesselation on a hexagonal grid (see illustrations fork = 4
and fork = 7
). (Because of this property, these numbers find application in mobile cellular communication networks.)See more characterizations in the OEIS page of the sequence.
##The challenge
Given a positive integer, output a truthy result if it is a Loeschian number, or a falsy result otherwise.
The program or function should handle (say in less than a minute) inputs up to 1000
, or up to data type limitations.
Code golf. Shortest wins.
##Test cases
The following numbers should output a truthy result:
1, 4, 7, 12, 13, 108, 109, 192, 516, 999
The following numbers should output a falsy result:
2, 5, 10, 42, 101, 102, 128, 150, 501, 1000