There may be several consecutive numbers in the factor of a positive integer n. For example, 630 can be decomposed into 3*5*6*7, where 5, 6, and 7 are 3 consecutive numbers. Given any positive integer n, it is required to write a program to find the maximum number of consecutive factors, and output the smallest continuous factor sequence.
Input format:
The input gives a positive integer N (1<n<2^31) in a row.
Output format:
First, the number of the longest continuous factor is output in line 1th, and then the smallest continuous factor sequence is output in line 2nd in the format of Factor 1* factor K 2*......*, where the factor is output in ascending order and 1 is not counted.
Input Sample:
630
Sample output:
3
5*6*7
Is the search, from each can divide the factor to start the continuous search,
until no longer divisible, return to find the next can divide the factor; the
only point is that the prime number outputs itself;
*/
#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;
the int find (int n,int fac,int l) //n is the remaining factor FAC for the next factor L is the length of the continuous factor
{
if (n%fac==0)
{
find (N/FAC, fac+1,l+1);
}
else
return l;
}
int main ()
{
int n,length=0,ans;
cin>>n;
for (int i=2; i<sqrt (n); i++)
{
if (n%i==0)
{
int l=find (n/i,i+1,1);
if (l>length)
{
length=l;
Ans=i
;
}}} if (length==0) //Description n is prime number
{
cout<<1<<endl;
cout<<n<<endl;
return 0;
}
cout<<length<<endl;
for (int i=0; i<length-1; i++)
cout<<ans+i<< "*";
cout<<ans+length-1<<endl;
}