Skip to content

Instantly share code, notes, and snippets.

@aakashns
Created June 22, 2012 01:06
Show Gist options
  • Save aakashns/2969636 to your computer and use it in GitHub Desktop.
Save aakashns/2969636 to your computer and use it in GitHub Desktop.
Prime Factorization of a Number
prime_factorization(long x)
{
long i; /* counter */
long c; /* remaining product to factor */
c = x;
while ((c % 2) == 0) {
printf("%ld\n",2);
c = c / 2;
}
i = 3;
while (i <= (sqrt(c)+1)) {
if ((c % i) == 0) {
printf("%ld\n",i);
c = c / i;
}
else i = i + 2;
}
if (c > 1) printf("%ld\n",c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment