public function fib($n)
    {
        if ($n < 3) return 1;
        $k = $n / 2;
        $a = $this->fib($k + 1);
        $b = $this->fib($k);
        if ($n % 2 == 1) {
            return $a * $a + $b * $b;
        } else {
            return $b * (2 * $a - $b);
        }
    }