Fibonacci Modified

題目來源:Fibonacci Modifiedspa

We define a modified Fibonacci sequence using the following definition:code

Given terms  and  where , term  is computed using the following relation:orm

 

 

For example, if term  and , term , term , term , and so on.blog

Given three integers, , and , compute and print term  of a modified Fibonacci sequence.three

Note: The value of  may far exceed the range of a -bit integer. Many submission languages have libraries that can handle such large results but, for those that don't (e.g., C++), you will need to be more creative in your solution to compensate for the limitations of your chosen submission language.ip

Input Formatci

A single line of three space-separated integers describing the respective values of , and .get

Constraintsinput

  •  may far exceed the range of a -bit integer.

Output Formatit

Print a single integer denoting the value of term  in the modified Fibonacci sequence where the first two terms are  and .

Sample Input

0 1 5

Sample Output

5

Explanation

The first two terms of the sequence are  and , which gives us a modified Fibonacci sequence of . Because , we print term , which is .

 

 

偷懶的Python版本:

1 in_str = raw_input()
2 
3 pre, aft, num = map(int, in_str.split())
4 
5 for i in range(num-2):
6     pre, aft = aft, pre + aft**2
7 
8 print aft
相關文章
相關標籤/搜索