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.

题目大意:

斐波那契数列中的每一项被定义为前两项之和。从1和2开始,斐波那契数列的前十项为:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

考虑斐波那契数列中数值不超过4百万的项,找出这些项中值为偶数的项之和。

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h> #define N 4000000 int a[]; void solve()
{
int a,b,c,n,count=;
a=,c=,b=;
n=;
while(c<=N)
{
c=a+b;
if(n%!=)
{
a=c;
}
else
{
b=c;
}
n++;
if(c%==)
{
count+=c;
}
}
printf("%d",count);
} int main()
{
solve();
return ;
}
Answer:
4613732

(Problem 2)Even Fibonacci numbers的更多相关文章

  1. (Problem 42)Coded triangle numbers

    The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...

  2. (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 ...

  3. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  4. (Problem 74)Digit factorial chains

    The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...

  5. (Problem 49)Prime permutations

    The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...

  6. (Problem 47)Distinct primes factors

    The first two consecutive numbers to have two distinct prime factors are: 14 = 2  7 15 = 3  5 The fi ...

  7. (Problem 36)Double-base palindromes

    The decimal number, 585 = 10010010012(binary), is palindromic in both bases. Find the sum of all num ...

  8. (Problem 34)Digit factorials

    145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are ...

  9. (Problem 28)Number spiral diagonals

    Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is forme ...

随机推荐

  1. perl 第十四章 Perl5的包和模块

    第十四章 Perl5的包和模块 by flamephoenix 一.require函数  1.require函数和子程序库  2.用require指定Perl版本二.包  1.包的定义  2.在包间切 ...

  2. jQuery.fn.extend与jQuery.extend 的区别

    1 jquery.extend 是jquery 静态的方法 实例 jQuery.extend({     liu: function(){         alert('liu');     } }) ...

  3. Google启封后依然不能用

    门事件周年纪念日过后一段时间,狗狗启封了,但撸主的狗狗仍旧不能用,突然想起来之前帆樯时候改动了某些配置,比方hosts文件,这个文件的路径为:C:\Windows\System32\drivers\e ...

  4. [置顶] 局部加权回归、最小二乘的概率解释、逻辑斯蒂回归、感知器算法——斯坦福ML公开课笔记3

    转载请注明:http://blog.csdn.net/xinzhangyanxiang/article/details/9113681 最近在看Ng的机器学习公开课,Ng的讲法循循善诱,感觉提高了不少 ...

  5. Phases of translation

    Phases of translation--翻译阶段 The C++ source file is processed by the compiler as if the following pha ...

  6. wget 无法下载jdk的处理办法

    完整语句:wget --no-cookie --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle. ...

  7. js中设置setInterval的注意点

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  8. 部署django - Apache + mod_wsgi + windows

    部署django - Apache + mod_wsgi + windows 1.环境 django 1.6.2 python 3.3 32位 apache 2.4.7 32位 一个可以使用的djan ...

  9. python--help

    python help 学习python的过程中,难免遇到一些生疏的东西,为此需要参看相关的文档说明. Linux下众所周知有man可以查找系统的命令帮助页:对于python也提供了自己的帮助文档的2 ...

  10. 设置textarea文本域不能调整大小 resize

    CSS3中新增了resize缩放属性,这个属性可以应用到任意元素.目前只有Webkit内核的浏览器才支持这个css3属性,即Google chrome和Apple safari都支持.而textare ...