You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
759 B

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
//判断素数
bool isPrime(int n) {
if (n < 2) return false;
for (int i = 2; i <= n / i; i++)
if (n % i == 0) return false;
return true;
}
//分解质因数
const int N = 110;
int a[N];
void divide(int n) {
int k = 0;
for (int i = 2; i <= n; i++) {
//为了多次获取同一个质因子
while (isPrime(i) && n % i == 0) {
a[k++] = i;
n /= i;
}
}
}
int main() {
int n = 1234;
divide(n);
printf("%d=", n);
for (int i = 0; i < N; i++) {
if (!a[i])break;
if (i > 0) printf("*");
printf("%d", a[i]);
}
return 0;
}