--Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
--1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
--By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
function list_iter()
local n =
local i =
local j =
return function()
if(i < n) then
tmp = i + j
j = i
i = tmp
return i
end
end
end local sum = ;
for i in list_iter() do
if(i % == ) then sum = sum + i end
end
print(sum)
相关文章
- Leetcode0002--Add Two Numbers 链表求和
- Codeforces 374 C. Travelling Salesman and Special Numbers (dfs、记忆化搜索)
- ZOJ 1095 Humble Numbers
- 9 C. Hexadecimal's Numbers
- Codeforces Round #452 (Div. 2) C. Dividing the numbers(水)
- 【Codeforces Round #452 (Div. 2) C】 Dividing the numbers
- java实现斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项。 n public class Solution_feibonaqi { public int Fibonacci(int n) { int result[] = { 0, 1 }; if (n < 2) { return result[n]; } int f0 = 0; int f1 = 1; int f2 = 0; for (int i = 2; i <= n; i++) { f2 = f1 + f0; f0 = f1; f1 = f2; } return f2; } public static void main(String[] args) { Scanner sc = new Scanner; int n = ; Solution_feibonaqi fei = new Solution_feibonaqi; ((n)); } }
- 633.平方数之和(Sum of Square Numbers)
- Codeforces 385C - Bear and Prime Numbers(素数筛+前缀和+hashing)
- Python——Fibonacci斐波那契数列的函数fib(n) 输出前20项(每项宽度符位置,右对齐),每行输出10个 递归和非递归实现