提交时间:2023-08-22 21:05:30
运行 ID: 99480
#include <iostream> using namespace std; bool isPrime(int num) { if (num <= 1) return false; for (int i = 2; i * i <= num; ++i) { if (num % i == 0) return false; } return true; } void printPrimeFactorization(int num) { std::cout << num << "="; for (int i = 2; i <= num; ++i) { if (isPrime(i)) { while (num % i == 0) { std::cout << i; num /= i; if (num != 1) { std::cout << "*"; } } if (num == 1) { break; } } } std::cout << std::endl; } int main() { int num; std::cin >> num; printPrimeFactorization(num); return 0; }