Fibonacci Modified

本文介绍了一个基于传统斐波那契数列的修改版数列,并提供了一个简单的Python实现来计算该数列的第n项。该数列定义为G(0) = 0, G(1) = 1, G(n) = G(n-1) + G(n-2)^2 (n > 1),并给出了一个示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目来源: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

 

转载于:https://www.cnblogs.com/fcyworld/p/7678213.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值