解题代码
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n, cnt, left, m, temp, j;
int main() {
scanf("%lld", &n);
ll sqr = (int)sqrt(1.0*n);
for (int i = 2; i <= sqr; i++) {
temp = n;
cnt = 0;
if (temp%i == 0) {
j = i;
while (1) {
if (temp%j == 0) {
cnt++;
temp /= j++;
}
else break;
}
if (cnt>m) {
left = i;
m = cnt;
}
}
}
if (!m) printf("%d\n%d", 1, n);
else {
printf("%lld\n", m);
for (ll i = left; i < left + m; i++) {
if (i != left) printf("*");
printf("%lld", i);
}
}
return 0;
}
测试结果
问题整理
1.质因子分解。
2.注意一下特判情况的分析。