https://www.hackerrank.com/challenges/fibonacci-modified/problem?isFullScreen=true
Fibonacci Modified | HackerRank
Compute the nth term of a Fibonacci sequence.
www.hackerrank.com
import math
import os
import random
import re
import sys
def fibonacciModified(t1, t2, n):
# Write your code here
a1, a2 = t1, t2
num = 1
while num<=n-2: #이미 2개의 선행인지가 주어져서
a3 = a1 + a2**2
a1 = a2
a2 = a3
num+=1
return a3
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
t1 = int(first_multiple_input[0])
t2 = int(first_multiple_input[1])
n = int(first_multiple_input[2])
result = fibonacciModified(t1, t2, n)
fptr.write(str(result) + '\n')
fptr.close()
'파이썬 코딩테스트 > 해커랭크' 카테고리의 다른 글
HackerRank / Sherlock and Cost / Python (0) | 2021.12.24 |
---|---|
HackerRank / The Maximum Subarray / Python (0) | 2021.12.22 |
HackerRank / Prim's(MST) : Special SubTree / Python (0) | 2021.12.12 |
HackerRank / Jack goes to Rapture / Python (0) | 2021.12.12 |
HackerRank / Kruskal (MST) : Really Special Subtree / Python (0) | 2021.12.11 |