(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.
题目大意:
斐波那契数列中的每一项被定义为前两项之和。从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的更多相关文章
- (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 ...
 - (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 ...
 - (Problem 70)Totient permutation
		
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
 - (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 ...
 - (Problem 49)Prime permutations
		
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...
 - (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 ...
 - (Problem 36)Double-base palindromes
		
The decimal number, 585 = 10010010012(binary), is palindromic in both bases. Find the sum of all num ...
 - (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 ...
 - (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 ...
 
随机推荐
- 利用bind搭建dns
			
下载bind,我下载的是bind-9.3.1rc1.tar.gz 我下载的文件放在/root目录下 进入目录解压缩 [root@linux root]#tar xfz bind-9.3.1rc1.ta ...
 - HDU 3466 Proud Merchants
			
题目大意:现在给出商品,有三个参数,记为pi,qi,vi,vi是商品的在你心里价值,pi是商品的价格,qi是你要买商品的时候至少需要的钱然后求可得的最大价值. 单词积累:Merchants 商人 t ...
 - 字符串模式匹配KMP算法
			
一篇不错的博客:http://www.cnblogs.com/dolphin0520/archive/2011/08/24/2151846.html KMP字符串模式匹配通俗点说就是一种在一个字符串中 ...
 - /export/App/zz/phantomjs-1.9.7-linux-x86_64/bin
			
/export/App/zz/phantomjs-1.9.7-linux-x86_64/bin
 - 【示例代码】HTML+JS 画图板源码分享
			
一个有趣的画图板, 用了 HTML5中的本地存储.下载.canvas 等技术,这个项目中用到了canvas 的很多基础功能,初学者可以学习一下 . 建议开发童鞋使用统一开发环境UDE来进行查看.调试. ...
 - Thrift对多接口服务的支持
			
Thrift对多接口服务的支持 Thrift在0.9.1版本之前,一直只提交了对单一接口服务的支持,即一个RPC服务器(对应一个端口)支持一个服务接口的实现. 但是很多时候,我们的服务不能实现在一个接 ...
 - JS 排列组合
			
function $CL(arr, n, noLC, arrDan) { //从arr中取n个组合,然后 var r = [], sum = 0; n = n - arrDan.length; (fu ...
 - SSIS CDC(Change Data Capture)组件在数据库中启用报错。  The error returned was 14234: 'The specified '@server' is invalid
			
昨天实验CDC,在数据库中执行以下语句的时候出错. EXEC sys.sp_cdc_enable_table @source_schema = N'stg', @source_name = N'CDC ...
 - OD调试篇3-小软件破解1
			
OD调试篇3-小软件破解1 要求如下图该软件需要改5个地方,其中1.2是软件未注册而设定限定的添加个数,3.4.5是软件显示的一些未注册的信息. 一. 1.按1运行程序,添加用户添加第五个时出现提示, ...
 - Linux学习之查找命令find
			
1.find -name 根据名称查找文件 *通配所有字符: ?统配单个字符 2.find -iname 根据名称不区分大小写 3.find -size 根据文件大小 find / -size + ...