本文主要是介绍PAT 甲级 1096 Consecutive Factors,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
PAT 甲级 1096 Consecutive Factors
#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifdef LOCALfreopen("input.txt", "r", stdin);
#endifint num, max_len = -1, now_len = 0, beg = 0, now_beg;cin >> num;for (int i = 2; i <= ceil(sqrt(num)); ++i) {if (num % i == 0) {int j = i;now_len = 0, now_beg = j;// 防止溢出long long tmp = j;while (num % tmp == 0) {++j, tmp *= j;}now_len = j - now_beg;if (now_len > max_len) {max_len = now_len, beg = now_beg;}}}if (max_len == -1) {// 小于等于ceil(sqrt(num))的没有num的因子,说明num是素数printf("1\n%d", num);}else {cout << max_len << endl;for (int i = 0; i < max_len; ++i) {if (i != 0) cout << "*";cout << i + beg;}}
}
这篇关于PAT 甲级 1096 Consecutive Factors的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!