#K34362. Efficient Fibonacci Computation

    ID: 25293 Type: Default 1000ms 256MiB

Efficient Fibonacci Computation

Efficient Fibonacci Computation

Given a non-negative integer \( n \), compute the \( n \)th Fibonacci number efficiently using memoization or iterative methods. The Fibonacci sequence is defined as follows:

\( F(0)=0, \ F(1)=1, \ F(n)=F(n-1)+F(n-2) \) for \( n \geq 2 \).

If \( n < 0 \), output the error message "n must be a non-negative integer". If the input is not a valid integer, output the error message "Invalid request. Please provide a valid integer for n."

inputFormat

Input is read from standard input (stdin) as a single line containing an integer ( n ).

outputFormat

Output the ( n )th Fibonacci number to standard output (stdout). If ( n ) is negative, output "n must be a non-negative integer". If the input is invalid (i.e., not an integer), output "Invalid request. Please provide a valid integer for n."## sample

10
55