#include #include typedef unsigned long long longnum; void print_prime_factorization(longnum num) { for (longnum prime = 2; num > 1; ++prime ) { longnum times = 0; for ( ; num % prime == 0; ++times ) num /= prime; if ( times > 0 ) printf("%llu^%llu ", prime, times); } } void print_prime_factors(longnum num) { longnum pows = 0; for (longnum prime = 2; num > 1; ++prime) { longnum times = 0; for ( ; num > 1 && num % prime == 0; ++times ) num /= prime; if ( times > 0 ) { if ( pows++ > 0 ) printf(" * "); printf("%llu", prime); if ( times > 1 ) printf("^%llu", times); } } if ( pows == 0 ) printf("%llu", num); } int main(int argc, char* argv[]) { for ( int i = 1; i < argc; ++i ) { longnum num = strtoull(argv[i], NULL, 10); printf("%llu = ", num); print_prime_factors(num); putchar('\n'); } return 0; }