码迷,mamicode.com
首页 > 其他好文 > 详细

Fibonacci Modified

时间:2017-10-16 22:16:17      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:sequence   get   value   chosen   play   mis   any   pytho   constrain   

题目来源:Fibonacci Modified

We define a modified Fibonacci sequence using the following definition:

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

 

 

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

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

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.

Input Format

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

Constraints

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

Output Format

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

 

Fibonacci Modified

标签:sequence   get   value   chosen   play   mis   any   pytho   constrain   

原文地址:http://www.cnblogs.com/fcyworld/p/7678213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!