HackerRank# Fibonacci Modified

原题地址

 

竟然64位都要爆,这是要大整数乘法的节奏吗?我才不要写大整数乘法呢,用Ruby干掉

 

代码:

1 # Enter your code here. Read input from STDIN. Print output to STDOUT

2 num = [0, 0]

3 num[0], num[1], n = readline.chomp.split(' ').map {|e| e.to_i}

4 (n - 2).times do

5     tmp = num[1] ** 2 + num[0]

6     num[0] = num[1]

7     num[1] = tmp

8 end

9 puts num[1]

 

你可能感兴趣的:(fibonacci)