読者です 読者をやめる 読者になる 読者になる

Project Euler 2

Problem 2

using System;

namespace PE {
    public class PE002 {
        public static void Calc() {
            const int n = 4000000;

            int a = 1;
            int b = 2;
            int sum = 2;
            while (b <= n) {
                int tmp = a + b;
                a = b;
                b = tmp;

                if (tmp % 2 == 0)
                    sum += tmp;
            }
            Console.WriteLine(sum);
        }        
    }
}