当前位置:网站首页>[PTA] l1-006 continuity factor

[PTA] l1-006 continuity factor

2022-04-23 20:23:00 Maybe

Original link

L1-006 Continuous factor

ac Code

Pay attention to the error prone points and optimization methods in the notes

#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
using namespace std;
int main() {
    
	int n;
	cin >> n;

	int len = 0, st = 0;
	for(int i = 2; i <= sqrt(n); i++) {
    //sqrt(n) Then there can be no continuity factor 
		int temp = n;
		if(!(temp % i)) {
    
			int templ = 0, tempst = i;
			int t = i;// Because it's a grouping factor , So it's possible to remove the front , Add the back , More cases of continuity factors , use t temporarily replace i 
			while(!(temp % t)) {
    // Here, the continuous factor does not refer to the divisible factor used , But in groups 
				temp /= t++;
				templ++;
			}
			if(templ > len) {
    
				len = templ;
				st = tempst;
			}
		}
	}


	if(len) {
    
		cout << len << endl;
		for(int i = st; i < st + len - 1; i++) {
    
			cout << i << '*';
		}
		cout << st + len - 1;
	}else{
    
		cout << 1 << endl << n;// Prime cannot find intermediate factor , Previous searches will not record , Number of individual outputs 1 And it itself  
	}
	return 0;
}

版权声明
本文为[Maybe]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232020000314.html