A1096 Consecutive Factors [因子分解]
程序员文章站
2022-06-07 11:45:32
...
#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 << "*";
}
}
}
上一篇: nginx配置多个站点的问题?
下一篇: 淡奶油怎么做冰淇淋?其实做法超简单!