我的代码
#include<iostream>
#include<math.h>
using namespace std;
bool isPrime(int n){
if(n == 2)
return 1;
for (int i = 2; i <= sqrt(n); ++i)
if(n % i == 0)
return 0;
return 1;
//判断是否是素数
}
void factorize(int n){
//质因数分解并输出
cout << n << "=";
for (int i = 2; i <= n; ++i){
if(isPrime(i))
while(n % i ==0){
cout << i;
if (n / i > 1)
cout << "*";
n /= i;
}
}
cout << endl;
}
int main(){
int a, b;
cin >> a >> b;
for (int i = a; i <= b; ++i)
factorize(i);
return 0;
}