// The prime factors of 13195 are 5, 7, 13 and 29.
//
// What is the largest prime factor of the number 600851475143 ?
using System;
using System.Collections.Generic;
using System.Text;
namespace projecteuler003
{
class Program
{
static void Main(string[] args)
{
F1();
}
private static void F1()
{
Console.WriteLine(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod());
DateTime timeStart = DateTime.Now;
long value = 600851475143;
int maxFactor = int.MinValue;
while (value != 1)
{
int sqrtValue = int.Parse(Math.Sqrt(value).ToString().Split('.')[0]);
if (value % 2 == 0)
{
value = value / 2;
maxFactor = 2;
}
for (int i = 3; i <= sqrtValue; i += 2)
{
if (value % i == 0)
{
//Console.Write(i + " ");
value /= i;
if (maxFactor < i)
{
maxFactor = i;
}
}
}
}
Console.WriteLine(maxFactor);
Console.WriteLine("Total Milliseconds is " + DateTime.Now.Subtract(timeStart).TotalMilliseconds + "\n\n");
}
}
}
/*
Void F1()
6857
Total Milliseconds is 14.0018
By GodMoon
*/
【ProjectEuler】ProjectEuler_003
最新推荐文章于 2025-06-18 10:13:17 发布
