OFFSET
1,2
COMMENTS
Maximum error on the first 99 terms = 3.3%. (See the Specht's site).
The first row of discs is placed on the base of the square. Then hexagonal packing is applied, row by row, as much as possible. We find a number N of discs. If n^2>N then the whole packing is replaced by the square one. Example: n=3 => N=8 but since n^2=9 we can indeed place 9 discs.
Note: useful only for n=2, 3, 4, 5, 6, 7.
FORMULA
a(n) = max(n^2,n*floor(1+2*(n-1)/sqrt(3)) - floor(floor(1+2*(n-1)/sqrt(3))/2));
PROG
(Matlab/Octave)
% Given here just for it is easier to understand than the formula.
% Warning: because of sqrt(3), which necessarily has a truncated represensation, results for large values of n may be incorrect.
% Hexagonal packing (upwards)
dh=sqrt(3)/2; nrows=floor(1+(n-1)/dh); % Number of rows
npairs=floor(nrows/2); % Number of pairs of rows
ndiscs=(2*n-1)*npairs; % Number of discs for the pairs
if nrows>2*npairs % Additional row (for n=1, 3, 5, 7, 8, etc.)
ndiscs=ndiscs+n;
end
a(n)=max(n^2, ndiscs); % Sometimes n^2 is better
(Python)
from math import isqrt
def A376215(n): return max(n**2, n*(m:=1+isqrt(((n-1)**2<<2)//3))-(m>>1)) # Chai Wah Wu, Nov 06 2024
CROSSREFS
KEYWORD
nonn,more
AUTHOR
Maurice Clerc, Sep 15 2024
STATUS
approved