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. 全新安装mysql最新版本

    写在前面: 下面写的东西只是最近安装的一个说明,是在系统中没存在mysql的情况下安装的,后期会根据官方文档写一个详细有价值的文档 安装原理:利用mysql官方的mysql_apt-repositor ...

  2. Linux 系统之Sysvinit

    子贡问为仁.子曰:“工欲善其事,必先利其器.居是邦也,事其大夫之贤者,友其士之仁者.”——孔子(春秋)<论语·卫灵公> [工欲善其事,必先利其器] 掌握一门技术,知道其发展历程是非常重要的 ...

  3. .NET study collection links

    Parameter Binding in ASP.NET Web API http://www.asp.net/web-api/overview/formats-and-model-binding/p ...

  4. HTML5 appcache

    参考http://www.zation.me/2013/05/28/build_offline_mobile_web_app.html 他的事件总结的比较好 checking:客户端正在检查manif ...

  5. 转: js中的getYear()函数的问题(推荐用 getFullYear())

    用了JS的getYear()方法,但是发现生成的代码竟然有108(本应该是2008),发现这是firefox下的问题. 然后google了一下,发 现原来是这样的:var today = new da ...

  6. c++ bitset使用

    A bitset is a special container class that is designed to store bits (elements with only two possibl ...

  7. 基于Visual C++2013拆解世界五百强面试题--题13-找最大公共子字符串

    编程实现:找出两个字符串中最大公共子字符串,如"abccade"和"dgcadde"的最大子字符串为"cad". 如果不考虑效率的话直接比较 ...

  8. fedora 安装pylab 并简单绘制三角函数

    pylab 由 三个部分组成:scipy, matplotlab, numpy三部分组成,安装时需要分别安装这三部分,在fedora中,可以使用命令: sudo dnf install python- ...

  9. iostream.h 和stdio.h区别

    stdio.h是C的标准I/O库,是以函数的方式向buffer写入或读取字符.输入输出是这样的printf(...);,scanf(...); iostream是C++的标准I/O库,引入了输入/输出 ...

  10. Ants(思维)

    Ants Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 12893   Accepted: 5637 Description ...