-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem003.cs
37 lines (33 loc) · 1011 Bytes
/
Problem003.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
namespace ProjectEulerSolutions.EulerProblems
{
public class Problem003
{
public static long Solution(double len)
{
long primeFactor = 0;
double maxFactor = Math.Sqrt(len);
for (long i = 1; i < maxFactor; i++)
{
if (len % i == 0)
{
bool isPrime = true;
double maxFactorPrime = Math.Sqrt(i);
for (long j = 2; j < maxFactorPrime; j++)
{
if (i % j == 0)
{
isPrime = false;
break;
}
}
if (isPrime && len % i == 0)
{
primeFactor = i;
}
}
}
return primeFactor;
}
}
}