Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Euler3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine(GetFactors(600851475143).Where(x => IsPrime(x)).Max());
- }
- static bool IsPrime(int number)
- {
- if (number == 1) return false;
- if (number == 2) return true;
- var limit = Math.Ceiling(Math.Sqrt(number));
- for (int i = 2; i <= limit; ++i)
- {
- if (number % i == 0) return false;
- }
- return true;
- }
- static List<int> GetFactors(long number)
- {
- int currentFactor = 2;
- List<int> result = new List<int>();
- while (number > 1)
- {
- if (number % currentFactor == 0)
- {
- result.Add(currentFactor);
- number /= currentFactor;
- currentFactor = 2;
- }
- else
- currentFactor++;
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement