#include <iostream> #include <cmath> using namespace std; bool prost(int m){ int k = 0; for (int i=2; i<=sqrt(m); i++) if (m % i == 0) k++; return k==0; }
int main(){ int n, r; int i = 1; cout << "n = ", cin >> n, cout << "\n"; if (prost(n)) { cout << "1 * " << n << " = " << n << "\n";} else { r = n; while (r != 1){ i++; if (prost(i)){ while (r % i == 0){ r = r / i; cout << i; if (r != 1) cout << "*"; } } } cout << "=" << n << "\n"; } return 0; }
#include <cmath>
using namespace std;
bool prost(int m){
int k = 0;
for (int i=2; i<=sqrt(m); i++)
if (m % i == 0) k++;
return k==0;
}
int main(){
int n, r;
int i = 1;
cout << "n = ", cin >> n, cout << "\n";
if (prost(n)) {
cout << "1 * " << n << " = " << n << "\n";}
else {
r = n;
while (r != 1){
i++;
if (prost(i)){
while (r % i == 0){
r = r / i;
cout << i;
if (r != 1) cout << "*";
}
}
}
cout << "=" << n << "\n";
}
return 0;
}
Пример:
n = 2720
2*2*2*2*2*5*17=2720