不學?
將來,別人壁咚的牆,就是你砌的
題目鏈接
連續因子
AC代碼,裏面有詳細的註解
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin>>n;
int len=0,start=0; ll pro=1; //len用來記錄連續因子長度;start用來記錄起始位置;Pro用作連乘迭代;
for (int i = 2; i <= sqrt(n); ++i) { //連續因子從2開始進行枚舉
pro=1;
for (int j = i; pro*j <= n; ++j) { //Pro*j用來控制第二層循環退出;
pro*=j; // 連乘迭代;
if (n%pro==0&&j-i+1>len) //n%pro==0用來記錄連乘因子是否爲n的連乘因子,當j-i+1的長度大於len才交換,這樣就可以滿足題目的要求最小連乘因子
{ // 這個時候就要記錄連乘因子的起始位置
start=i;
len=j-i+1;
}
}
}
if (start==0) //如果start==0,說明能爲一個素數
{
start=n;
len=1;
}
cout<<len<<endl<<start;
for (int k = start+1; k < start+len; ++k) {
cout<<"*"<<k;
}
cout<<endl;
return 0;
}