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. [LeetCode]题解(python):080-Remove Duplicates from Sorted Array II

    题目来源: https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 题意分析: 跟定一个排好序的数组.修改这个数组使 ...

  2. 我的第一个REST客户端程序!

    Delphi:XE8 看了好几天的资料了,也没有弄出来一个REST程序,尝试了XE8中带的例子,也都没有搞懂.我在网上不断搜索,看是否能够找到适合自己的文章,希望能够做出来一个REST的小例子,万幸, ...

  3. BEANUTIL 对象转JSON

    package cn.com.softmap.cache.util; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutp ...

  4. 最佳实践:Windows Azure 网站 (WAWS)

     编辑人员注释:本文章由 Windows Azure 网站团队的项目经理Sunitha Muthukrishna 撰写. Windows Azure 网站 (WAWS) 允许您在 Windows ...

  5. 宣布与 NBC 合作直播索契冬季奥运

     奥运开始的那天早些时候,NBC 和 Microsoft 宣布选择 Windows Azure 媒体服务为 2014 年俄罗斯索契冬奥会提供现场直播.与以往不同,以往的冬奥会采用了有限的流,但本届 ...

  6. 如何让HTML的编写更具结构性

    首先声明,我不是搞技术的,很多词汇写的不够专业,但作为一枚菜鸟,我站在菜鸟的角度,来讲述我在学习技术的过程中所遇到的问题,和解决的方案. 入门HTML还算简单,无非是先写好固定的三对开闭标签结构:ht ...

  7. ASP.NET上传文件的三种基本方法

    ASP.NET依托.net framework类库,封装了大量的功能,使得上传文件非常简单,主要有以下三种基本方法. 方法一:用Web控件FileUpload,上传到网站根目录. Test.aspx关 ...

  8. 引用类型List<T>的比较

    一:重新Equals和GetHashCode方法 /// <summary>    /// 描    述:弹出模型对象列表比较器(根据ID比较)    /// </summary&g ...

  9. java键盘录入

    System.out:标准输出设备(默认是:控制台) System.in:标准输入设备(默认是:键盘) --------------------- InputStream in = System.in ...

  10. oracle 开发笔记“跨数据库查询复制”

    1.方法一:创建DBL(data base link) CREATE PUBLIC DATABASE LINK 数据链名称 CONNECT TO 登陆用户名 IDENTIFIED BY 密码 USIN ...