Function
Define a functionf(n)=(f(n-1)+1)/f(n-2). You already got f(1) and f(2). Now, give you a numberm, please find the value of f(m).
Input
There are several test cases. Each casecontains three integers indicating f(1), f(2) and m ( 1 <= f(1), f(2), m<= 1000,000,000).
Output
For each case, please output the value of f(m), rounded to 6 decimal places.
SampleInput
1 1 3
SampleOutput
2.000000
这道题我第一感觉是用递归,但看到( 1 <= f(1), f(2), m<= 1000,000,000)。递归肯定是会卡掉的,用循环做肯定也会超时。我试着用几个小数据输出F(1)~F(20),发现f(n)是有规律的每5个数一循环。也就是f(6)~f(10)的值分别与f(1)~f(5)一一对应。知道规律就容易做了,只需要计算f(1)~f(5)就行了。将m对5取余找出f(m)的结果就行了。。
这道题由于保留6位小数提交可能出现WA的情况,我想应该是精度问题导致最后一位小数的值会出现误差。