﻿PAT(A) 1096. Consecutive Factors (20)-Ocrosoft

PAT(A) 1096. Consecutive Factors (20)

Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive numbers. Now given any positive N, you are supposed to find the maximum number of consecutive factors, and list the smallest sequence of the consecutive factors.

Input Specification:

Each input file contains one test case, which gives the integer N (1<N<231).

Output Specification:

For each test case, print in the first line the maximum number of consecutive factors. Then in the second line, print the smallest sequence of the consecutive factors in the format “factor[1]*factor[2]*…*factor[k]”, where the factors are listed in increasing order, and 1 is NOT included.

Sample Input:

```630
```

Sample Output:

```3
5*6*7
```
```#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cctype>
#include <climits>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
#define strend string::npos
#define ms(a) memset(a,0,sizeof(a))
#define  rep(a,v,b) for(int a=v;a<b;a++)
#define  repe(a,v,b) for(int a=v;a<=b;a++)
typedef long long LL;
const LL LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const int MAXN = 300000 + 10;
const int MOD = 1000000009;
LL GCD(LL a, LL b)
{
if (!b)return a;
return GCD(b, a%b);
}
/*(◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕)*/
/*(◕‿‿◕) 签订契约，成为马猴烧酒吧! (◕‿‿◕)*/
/*(◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕) (◕‿‿◕)*/
using namespace std;
int main()
{
int n; cin >> n;
int ansi = 0, ansj = 0, flag = 0;
for (int len = 12; len >= 1 && !flag; len--)
{
int lim = sqrt(n) + 1;
for (int i = 2; i <= lim&&!flag; i++)
{
int mul = i;
for (int j = 1; j < len; j++)
mul *= i + j;
if (n%mul == 0)flag = 1, ansi = i, ansj = len;
}
}
if (!ansi)
{
printf("1\n%d\n", n);
return 0;
}
printf("%d\n", ansj);
for (int i = 1; i < ansj; i++)
printf("%d*", ansi + i - 1);
printf("%d\n", ansi - 1 + ansj);
return 0;
}```