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

Project Euler 3

Problem 3

using System;
using System.Collections.Generic;

namespace PE {
    public class PE003 {
        public static void Calc() {
            long n = 600851475143;

            List<long> factors = new List<long>();
            long x = 3;
            while (x*x <= n) {
                if (n % x == 0) {
                    factors.Add(x);
                    n /= x;
                }
                else {
                    x += 2;
                }
            }

            if (n > 1)
                factors.Add(n);

            Console.WriteLine(factors[factors.Count-1]);
        }
    }
}