Skip to content

Instantly share code, notes, and snippets.

@aterga
Created October 12, 2012 08:17
Show Gist options
  • Save aterga/3877970 to your computer and use it in GitHub Desktop.
Save aterga/3877970 to your computer and use it in GitHub Desktop.
Representing naturals by sequence of prime factors
#include <vector>
typedef int num_t;
std::vector<num_t> *get_prime_factors(num_t num)
{
std::vector<num_t> *list = new std::vector<num_t>();
num_t start_num = num;
for (num_t i = 2; i <= num; i ++)
{
while (num % i == 0)
{
list->push_back(i);
num /= i;
}
}
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment