#C13041. Efficient Fibonacci Sequence Computation
Efficient Fibonacci Sequence Computation
Efficient Fibonacci Sequence Computation
Given a positive integer \(n\), compute the \(n\text{-th}\) number in the Fibonacci sequence. The Fibonacci sequence is defined as follows:
\(F_1 = 0, F_2 = 1\), and for \(n \geq 3\), \(F_n = F_{n-1} + F_{n-2}\).
Your task is to read an integer from standard input, compute \(F_n\) using an iterative approach that runs in \(O(n)\) time and uses \(O(1)\) space, and then print the result to standard output. If the input is not a positive integer, the program should output an appropriate error message.
inputFormat
The input consists of a single line containing one integer \(n\) \((1 \leq n \leq 10^6)\), representing the position in the Fibonacci sequence.
outputFormat
Output the \(n\text{-th}\) Fibonacci number. If \(n\) is not a positive integer, output an error message: "n must be a positive integer".
## sample1
0