Showing posts with label Project Euler. Show all posts
Showing posts with label Project Euler. Show all posts

Thursday, June 21, 2012

Project Euler Problem4[C#]


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectEuler
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Problem4(600851475143UL));

        }
        /// <summary>
        /// http://projecteuler.net/problem=3
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public static ulong Problem4(ulong number)
        {
            ulong i = 2;
            while (i * i < number)
            {
                while (number % i == 0)
                {
                    number = number / i;

                }
                i = i + 1;
            }
            return number;

        }

    }
}