Skip to content

Instantly share code, notes, and snippets.

@JackDraak
Created March 6, 2017 08:00
Show Gist options
  • Save JackDraak/0a57be7174cb154faae1dda181d02316 to your computer and use it in GitHub Desktop.
Save JackDraak/0a57be7174cb154faae1dda181d02316 to your computer and use it in GitHub Desktop.
recursive method
void GetPrimeFactors(uint64_t number)
{
if (number == 2)
{
primeFactors.push_back(number);
return;
}
int max = floor(sqrt(number));
uint64_t factor;
for (uint64_t n = max; n > 1; n--)
{
if (IsPrime(n))
{
int remainder = number % n;
GetPrimeFactors(remainder);
primeFactors.push_back(n);
}
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment