求助
查看原帖
求助
653212
shensiyuan2011楼主2023/12/17 17:18
#include <bits/stdc++.h>
using namespace std;
map <long long, long long> p;
long long x[10000], cnt;
int n, cn = 1;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	for (long long j = 2; j <= n / j; j++) {
		if (n % j == 0) {
			x[cnt++] = j;
			while (n % j == 0) {
				n /= j;
				p[j]++;
			}
		}

	}
	if (cnt == 0) {
		cout << n;
		return 0;
	}
	if (n >= 1)
		x[cnt++] = n, p[n]++;
	if (p[x[0]] > 1)
		cout << x[0] << "^" << p[x[0]];
	else
		cout << x[0];
	for (int i = 1; i < cnt; i++) {
		if (p[x[i]] > 1)
			cout << " * " << x[i] << "^" << p[x[i]];
		else
			cout << " * " << x[i];
	}
	return 0;
}

额啊,样例都过了,为什么一个测试点都没过!

全wa

2023/12/17 17:18
加载中...