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);
}
}
继续欧拉
最新推荐文章于 2025-05-15 09:37:32 发布
本文通过一个Java程序实现计算斐波那契数列中小于400万的所有偶数项之和。该程序使用递归方法生成数列,并累加符合条件的偶数值。
1632

被折叠的 条评论
为什么被折叠?



