tle里说丰年 听取tle声1片
查看原帖
tle里说丰年 听取tle声1片
1165586
lizishi楼主2025/1/31 08:40

#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		while (n % 2 == 0) {
			n /= 2;
			cout << 2 << ' ';
		}
		while (n % 3 == 0) {
			n /= 3;
			cout << 3 << ' ';
		}
		for (int j = 5; j <= n; j += 4) {
			while (n % j == 0) {
				n /= j;
				cout << j << ' ';
			}
			j += 2;
			while (n % j == 0) {
				n /= j;
				cout << j << ' ';
			}
			if (n == 1) {
				break;
			}
		}
		cout << endl;
	}
	return 0;
}

O(n)O(\sqrt n)

2025/1/31 08:40
加载中...