#K1471. Sum of Even Fibonacci Numbers Up To M

    ID: 24195 Type: Default 1000ms 256MiB

Sum of Even Fibonacci Numbers Up To M

Sum of Even Fibonacci Numbers Up To M

You are given a positive integer M. Your task is to compute the sum of all even Fibonacci numbers that do not exceed M. The Fibonacci sequence is defined as follows:

\(F(1)=1,\ F(2)=2,\) and for \(n>2,\ F(n)=F(n-1)+F(n-2)\).

Only include the even-valued terms in the sequence when they are \(\leq M\). Please read the input from standard input and print the output to standard output.

inputFormat

A single integer M representing the upper bound.

outputFormat

Output a single integer which is the sum of all even Fibonacci numbers not exceeding M.## sample

1000
798