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个斐波那契数的 ...
随机推荐
- 【Mac】【问题】
[一]export: `PATH;': not a valid identifier 可能是环境变量配的有问题 一般是~/.bash_profile 多了空格或是多了$符号之类的
- 在webstorm中配置sass的自动编译,并且可以指定编译后的css的目录.
参考: WebStorm-2018.2-Help-Sass, Less, and SCSS 作者:tobyDing链接:https://www.jianshu.com/p/0fe52f149cab來源 ...
- js for 循环示例
//for 循环 ,,,,,,]; ; i < array.length; i++) { console.log(i,array[i]); } //for in ,,,,,,]; for(let ...
- .Net Core 管道中的ConfigureServices 和Configure
ConfigureServices 就是配置服务器的DI容器 把需要的中间件等一些东西添加到DI容器 最后都是添加到IServiceCollection里面 比如 services.AddI ...
- 区间DP 基本题集
51 Nod 1021 石子归并 模板题,敲就完事了,注意一下这种状态转移方程有个四边形的优化(时间) #include <cstdio> #include <iostream> ...
- EM公式推导
纯手写,字很丑,人也很丑.. E步公式是怎么来的呢?推导步骤如下, EM算法核心思想是先给定初始θ,求样本X,和隐变量z的期望(实际上是个函数),可以画一个曲线,M步:然后不断滑动θ,找到使得期望最大 ...
- NopCommerce源码架构详解
NopCommerce源码架构详解--初识高性能的开源商城系统cms 很多人都说通过阅读.学习大神们高质量的代码是提高自己技术能力最快的方式之一.我觉得通过阅读NopCommerce的源码,可以从 ...
- pta
一:实验代码 include <stdio.h> char theValue[10] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j ...
- Vue之添加全局变量
定义全局变量 原理: 设置一个专用的的全局变量模块文件,模块里面定义一些变量初始状态,用export default 暴露出去,在main.js里面使用Vue.prototype挂载到vue实例上面或 ...
- Maven中基于POM.xml的Profile来动态切换配置信息
[转载:https://blog.csdn.net/blueheart20/article/details/52838093] 1. Maven中的profile设置 Maven是目前主流的项目代码结 ...