OFFSET
1,2
COMMENTS
The octagon is obtained from a square of side 3n-2 cells by removing a triangle of cells from each of the four corners.
LINKS
Paolo Xausa, Table of n, a(n) for n = 1..10000
Anatoliy A. Abramov, Illustration of initial terms
Index entries for linear recurrences with constant coefficients, signature (1,2,-2,-1,1).
FORMULA
a(n) = k*(k + 1)/2 - floor(n^2/4), where k = ceiling((n + 2*(n - 1))/2).
G.f.: x*(1 + x + 4*x^2 + x^3)/((1 - x)^3*(1 + x)^2). - Stefano Spezia, May 07 2023
EXAMPLE
For n=3, the octagon is a square of side 3n-2 = 7 with corners chopped to leave each side with 3 "*",
* * *
* * * * *
* * * * * * *
@ @ @ @ * * *
@ @ @ * * * *
@ * * * *
* * *
The a(3) = 8 cells marked "@" are an eighth of the figure and are the primitive cells in the sense that other cells map to them by rotations or reflections.
MATHEMATICA
LinearRecurrence[{1, 2, -2, -1, 1}, {1, 2, 8, 11, 22}, 100] (* Paolo Xausa, Oct 16 2023 *)
PROG
(Java)
import java.util.function.Function;
import java.util.stream.IntStream;
public class Main {
private static int A362869(int n) {
Function<Integer, Integer> trianglarNumber = p -> p * (p + 1) / 2;
Function<Integer, Integer> quarterOfSquareNumber = p -> p * p / 4;
int k = (n + 2 * (n - 1) + 1) / 2;
return trianglarNumber.apply(k) - quarterOfSquareNumber.apply(n);
}
public static void main(String[] args) {
IntStream.range(1, 100).forEach(n -> System.out.print(A362869(n) + ", "));
}
}
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Anatoliy A. Abramov, May 07 2023
STATUS
approved