Finding Prime Factors of a Number

Still playing around with D (it’s REALLY fast [well, compared to Ruby :)]). Here is some code to find prime factors of a number. This could probably be a lot more concise but I like to favor read-able, simple code over one-line-migraines.

import std.stdio;

/*
Check smaller tests against: http://www.math.wustl.edu/cgi-bin/primes
*/

int main(char[][] args)
{
	writefln("Euler3.d
	
	The prime factors of 13195 are 5, 7, 13 and 29.

	What is the largest prime factor of the number 317584931803?
	");

	ulong n = 317584931803;
	ulong[] factors = [];
	writefln("Prime Factors of %s", n);
	printArray(findPrimeFactors(n,factors));
  	return 0;
}

struct primeFactor {
	ulong prime, remainder;
}

ulong[] findPrimeFactors(ulong n, ulong[] factors)
{
	primeFactor* pf = findFirstPrimeFactor(n);
	
	factors = factors ~ [pf.prime];
	if (pf.remainder == 1)
		return factors;
	else
		return findPrimeFactors(pf.remainder, factors);
		
	//should never get here but required to compile
	return factors;
}

primeFactor* findFirstPrimeFactor(ulong remainder)
{
	primeFactor* pf = new primeFactor;
	
	ulong start = 2;

	while ( (remainder % start) != 0 && start < = remainder)
		start = findNextPrime(start);

	pf.prime = start;
	pf.remainder = remainder / start;
	return pf;
}

ulong findNextPrime(ulong start)
{
	do {
		start++;
	} while (isPrime(start) == false)
	return start;
}

//from http://www.thescripts.com/forum/thread215055.html
bool isPrime(ulong n)
{
	if (n < 2) return false;
	
	for (ulong c = 2; c < n; c++)
		if ((n % c) == 0) return false;

	return true;
}

void printArray(ulong[] arr)
{
	for (int i = 0; i < arr.length; i++)
		writefln(arr[i]);
}