Skip to main content
5 of 10
added 101 characters in body
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

Is this number Loeschian?

A positive integer k is a Loeschian number if

  • k can be expressed as i*i + j*j + i*j for i, 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 as i*i + j*j + i*j for i, j non-negative integers. (For each pair of integers i, j there's a pair of non-negative integers that gives the same k)

  • There is a set of k contiguous hexagons that forms a tesselation on a hexagonal grid (see illustrations for k = 4 and for k = 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
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372