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 (131).

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

坑点:long long 的使用,否则最后一个点一直报超时。

附上C++的最大最小值代码:

#include

cout<< numeric_limits::max() << endl;
	cout<< numeric_limits::max() <::max() <::max() <::max() <::min() << endl;
	cout<< numeric_limits::min() <::min() <


AC代码:

#include
#include
#include
using namespace std;

int main()
{
	long long n;
	int ans[2] = { 0 };
	scanf("%lld", &n);
	for(long long i = 2; i * i <= n; i++)
	{
		if(n % i == 0)
		{
			if(ans[0] == 0)
			{
				ans[0] = ans[1] = i;
			}
			long long sum = i;
			int j = i;
			while(n % sum == 0 && j - i < 12)
			{
				j++;
				sum *= j;
			}
			j--;
			if(j - i > ans[1] - ans[0])
			{
				ans[0] = i;
				ans[1] = j;
			}
		}
	}
	if(ans[0] == 0)
	{
		printf("1\n%lld", n);
	}
	else
	{
		printf("%d\n", ans[1] - ans[0] + 1);
		for(int i = ans[0]; i <= ans[1]; i++)
		{
			if(i != ans[0])
				printf("*");
			printf("%d", i);
		}
	}
	return 0;
}



你可能感兴趣的:(PAT甲级,c++,筛素数)