PTA Consecutive Factors (20分)

It is the human mind that releases infinite light, and it is also the human mind that creates boundless darkness. Light and darkness are intertwined and fight together. This is the world for which we are nostalgic and helpless.

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<2​31​​).

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 <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include<climits>//INT_MAX
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
typedef long long ll;
using namespace std;
int const mod=1e9+7;
const int maxn=3e5+10;
int n,mx,fg;
int main(){
	cin>>n;
	for(int i=2;i<=(int)sqrt(n);i++){
		int j=i,ct=0,ls=n;
		while(ls%j==0){
			ls/=j;
			j++;
			ct++;
		}
		if(ct>mx){
			mx=ct;
			fg=i;
		}
	}
	if(fg==0)
		cout<<1<<endl<<n<<endl;
	else{
		cout<<mx<<endl<<fg;
		for(int i=1;i<mx;i++)
			cout<<'*'<<fg+i;
	}
	return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_44170305/article/details/108414731