Problem 2: Even Fibonacci numbers
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.
#斐波那契数列,python有个简易写法
s = 0 # 求和
a, b = 1, 1 # 赋初始值
n = 4000000 # 最大数
while True:
a, b = b, a+b
if b >= n:
break
if b % 2 == 0: # 满足偶数项条件
s += b
print(s)
%time %run ol002.py
4613732
Wall time: 2 ms
Problem 2: Even Fibonacci numbers的更多相关文章
- Codeforces 446-C DZY Loves Fibonacci Numbers 同余 线段树 斐波那契数列
C. DZY Loves Fibonacci Numbers time limit per test 4 seconds memory limit per test 256 megabytes inp ...
- Fibonacci Numbers
Fibonacci Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Colossal Fibonacci Numbers! UVA 11582 寻找循环节
/** 题目:Colossal Fibonacci Numbers! UVA 11582 链接:https://vjudge.net/problem/UVA-11582 题意:f[0] = 1, f[ ...
- Project Euler 435 Polynomials of Fibonacci numbers (矩阵快速幂)
题目链接: https://projecteuler.net/problem=435 题意: The Fibonacci numbers $ {f_n, n ≥ 0}$ are defined rec ...
- codeforces 446C DZY Loves Fibonacci Numbers(数学 or 数论+线段树)(两种方法)
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation F1 ...
- cf446C DZY Loves Fibonacci Numbers
C. DZY Loves Fibonacci Numbers time limit per test 4 seconds memory limit per test 256 megabytes inp ...
- (Problem 21)Amicable numbers
Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into ...
- Codeforces Round #FF 446 C. DZY Loves Fibonacci Numbers
參考:http://www.cnblogs.com/chanme/p/3843859.html 然后我看到在别人的AC的方法里还有这么一种神方法,他预先设定了一个阈值K,当当前的更新操作数j<K ...
- HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)
HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意: 求第n个斐波那契数的 ...
随机推荐
- Vue-admin工作整理(七):路由的切换动效
思路就是通过 transition-group 这个组件来对多组件进行控制,效果是通过样式来写,transition-group要有指定的key值,样式中通过name来命名类的名字 <templ ...
- vmstat命令参数介绍
vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况.这个命令是我查看Linux/Unix最 ...
- postgres 11 单实例最大支持多少个database?
有人在pg8时代(10年前)问过,当时说10000个没问题,而且每个db会在/base下建立1个文件夹, 文件ext3只支持32000个子文件夹,所以这是上限了. 而现在早就ext4了,根本没有限制了 ...
- gdb 命令汇总
https://ftp.gnu.org/old-gnu/Manuals/gdb/html_node/gdb_109.html whatis expr 举例 whatis uint64 -& ...
- 雷林鹏分享:Laravel 安装
前面我们介绍我了 composer安装,这里我们接着来介绍 Laravel框架的安装. 这里我们安装的是laravel 4 项目下载地址:https://github.com/laravel/lara ...
- 小程序md5加密
function md5(string) { var x = Array(); var k, AA, BB, CC, DD, a, b, c, d; , S12 = , S13 = , S14 = ; ...
- Linux删除/boot后该如何恢复
一.其实不光boot目录被删除,也有系统启动不起来等,一直因为/boot这个目录的的问题,今天就来解决一下 Centos 6 1.进入救援,先修复vmlinz(内核) chroot /mnt/sysi ...
- 【C#】【对象转XML】xml序列化
笔记:xml序列化 /// <summary> /// xml序列化 /// </summary> /// <param nam ...
- C#操作SQLServer2012类
public class SqlServerService { public string CONN_STRING { get; set; } = "Data Source=.;Databa ...
- Linux系统vim几个常见配置
1.编辑配置文件:vim ~/.vimrc 2.配置文件写入以下内容 偷懒就截图上传了