欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

A1096 Consecutive Factors [因子分解]

程序员文章站 2022-06-07 11:45:32
...

A1096 Consecutive Factors [因子分解]

#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<time.h>
#include<math.h>
using namespace std;
typedef long long ll;
int main()
{
	int n; cin >> n;
	int sqr = sqrt(n), length = 0, k = 0;
	if (n >= 4)
	{
		for (int i = 2; i <= sqr; i++)
		{
			int temp = 1, j = i;
			while (1)
			{
				temp *= j;
				if (n % temp != 0) break;
				if (j - i + 1 > length)
				{
					k = i;
					length = j - i + 1;
				}
				j++;
			}
		}
	}
	else
	{
		for (int i = 2; i <= n; i++)
		{
			int temp = 1, j = i;
			while (1)
			{
				temp *= j;
				if (n % temp != 0) break;
				if (j - i + 1 > length)
				{
					k = i;
					length = j - i + 1;
				}
				j++;
			}
		}
	}
	if (length == 0) //质数
	{
		cout << "1" << endl;
		cout << n << endl;
	}
	else
	{
		cout << length << endl;
		for (int i = 0; i < length; i++)
		{
			cout << k+i;
			if (i < length - 1)
				cout << "*";
		}
	}
}