继续欧拉

package com.yao.app.euler;

public class Euler2 {

	public static void main(String[] args) {
		int limit = 4000000;
		int result = 0;
		int sum = 0;
		int n = 1;
		while (result < limit) {
			result = f(n);
			if (result % 2 == 0)
				sum += result;
			n++;
		}
		System.out.println(sum);

	}

	private static int f(int n) {
		if (n == 2)
			return 2;
		if (n == 1)
			return 1;
		return f(n - 1) + f(n - 2);
	}
}

你可能感兴趣的:(F#)