这个题换一种思路会方便许多,用n %(连续数的乘积)若==0,则满足条件。
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, maxLen = 0, start, End;
scanf ("%d", &n);
for (int i = 2; i <= (int)sqrt(n) + 1; i++) {
int temp = 1;
int j = i;
while(j <= (int)sqrt(n) + 1) {
temp *= j;
if (n % temp != 0) break;
j++;
}
if (j - i > maxLen) {
maxLen = j - i;
start = i;
End = j;
}
}
if (maxLen == 0) {
cout << 1 << endl;
cout << n << endl;
return 0;
}
cout << maxLen << endl;
for (int i = start; i < End; i++) {
if (i != start) printf ("*");
printf ("%d", i);
}
}