Problem2

问题描述
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.


就是求出满足小于4000000,并且是偶数的Fibonacci数的和。

public long Count1(){
		long result = 0;
		int start1 = 1;
		int start2 = 1;
		int end = 4000000;
		
		int cur ;
		do{
			cur = start1 + start2;
			if(cur%2==0){
				result += cur;
			}
			start1 = start2;
			start2 = cur;
		}while(start2<4000000);
		return result;
	}

你可能感兴趣的:(em)