Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created December 30, 2019 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/76411e95071ee75dad612c736fce7953 to your computer and use it in GitHub Desktop.
Save thinkphp/76411e95071ee75dad612c736fce7953 to your computer and use it in GitHub Desktop.
Fundamental Theorem of Arithmetic.
#include <stdio.h>
int main(int argc, char const *argv[])
{
int n, fm, i;
printf("%s", "n=");
scanf("%d", &n);
i = 2;
do {
fm = 0;
while(n % i == 0) {
fm++;
n /= i;
}
if(fm!=0) printf("%d^%d + ", i, fm);
i++;
} while( n != 1);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment