Sha256: d6bfcd74a5cce889e6dca54a8e8a0f4e79bd00960e95afe7aca586eadd64d60d
Contents?: true
Size: 564 Bytes
Versions: 71
Compression:
Stored size: 564 Bytes
Contents
#include "prime_factors.h" #include <math.h> /** * find prime factors: brute force version * https://en.wikipedia.org/wiki/Trial_division */ size_t find_factors(uint64_t n, uint64_t factors[static MAXFACTORS]) { int count = 0; while ((n % 2 == 0) && (count < MAXFACTORS)) { factors[count++] = 2; n /= 2; } for (uint64_t i = 3; (i <= sqrt(n)) && (count < MAXFACTORS); i += 2) { while (n % i == 0) { factors[count++] = i; n /= i; } } if (n > 2) { factors[count++] = n; } return count; }
Version data entries
71 entries across 71 versions & 1 rubygems