MathPHP\Sequence\Advanced::magicSquares PHP Method

magicSquares() public static method

https://oeis.org/A006003 https://edublognss.wordpress.com/2013/04/16/famous-mathematical-sequences-and-series/ n(n² + 1) M = --------- 2 Example: n = 6 Sequence: 0, 1, 5, 15, 34, 65 Array index: 0, 1, 2, 3, 4, 5,
public static magicSquares ( integer $n ) : array
$n integer How many numbers in the sequence
return array
    public static function magicSquares(int $n) : array
    {
        if ($n < 0) {
            return [];
        }
        $M = [];
        for ($i = 0; $i < $n; $i++) {
            $M[] = $i * ($i ** 2 + 1) / 2;
        }
        return $M;
    }