Project Euler questions are primarily about math. This isn't really the place to practice object-oriented programming. In fact, trying to model the problem literally will lead you to a suboptimal solution.
The "right" algorithm is very simple, and involves no primality testing.
The Answer
method could be a read-only property. II wouldn't bother with an IsFactor()
method at all — if you just write it as a modulo test, there is no confusion about the order the parameters.
class ProjectEuler3
{
private long number;
public ProjectEuler3(long number)
{
this.number = number;
}
public long Answer
{
getGetAnswer()
{
long n = this.number;
while (n % 2 == 0)
{
n /= 2;
}
for (long factor = 3; factor < n; factor += 2)
{
while (n % factor == 0)
{
n /= factor;
}
}
return n;
}
}
}