#include<iostream> #include<cmath> using namespace std; bool isPrime(int n) { if (n == 1) { return false; } for (int i = 2; i <= sqrt(n); ++i) { if (n % i == 0) { return false; } } return true; } int Prime[10000]; int main() { int j = 0; for (int i = 2; i <= 10000; ++i) { if (isPrime(i)) { Prime[j++] = i; } } int n; cin >> n; cout << n << "="; while (1) { int i = 0; while (n != 1) { while (n % Prime[i] == 0) { n /= Prime[i]; if (n != 1) { cout << Prime[i] << "*"; } else if (n == 1) { cout << Prime[i]; return 0; } } ++i; } } } |
Double click to view unformatted code.