Pentagonal numbers are figurate numbers that extend the concept of triangular and square numbers. The nth pentagonal number is given by the formula:
P(n) = n(3n - 1) / 2
where n is a positive integer (1, 2, 3, ...).
Your task is to implement a function `pentagonal(n)` that returns the nth pentagonal number as an integer.
Input: A single positive integer `n` (1 ≤ n ≤ 10^6).
Output: The nth pentagonal number as an integer.
You can assume that the input is always valid based on the constraints.
Constraints
1 ≤ n ≤ 10^6
Time complexity: O(1) (using the formula directly).
Space complexity: O(1).