TLE 70
查看原帖
TLE 70
1058749
King_and_Grey楼主2024/5/31 15:09
#include <bits/stdc++.h>
using namespace std;
#define in long long
bool isPrime(int x) {
	if(x == 1){
		return false;
	}
	if (x == 2 || x == 3 || x == 5 || x == 7) {
		return true;
	}
	if (x % 6 != 1 && x % 6 != 5) { 
		return false;
	}
	int tmp = sqrt(x);
	for (int i = 5; i <= tmp; i += 6) {
		if (x % i == 0 || x % (i + 2) == 0) {
			return false;
		}
	}
	return true;
}
in n,i = 2,ans;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n;
	if(isPrime(n) == true) {
		cout<<n<<endl;
		return 0;
	}else{
		while(n != 1 && isPrime(n) == false){
			if(isPrime(i) == false || n % i != 0){
				i++;
				continue;
			}
			else if(n % i == 0){
				while(n % i == 0){
					ans++;
					n /= i;
				}
				if(ans == 1){
					cout << i << " * ";
				}else if (ans > 1 && n > 1){
					cout << i << "^" << ans << " * ";
				}else{
					cout << i << "^" << ans << endl;
					return 0;
				}
				ans = 0;
			}
			if (isPrime(n) == true){
				cout << n << endl;
				return 0;
			}
		}
		cout << n << endl;
	}
	return 0;
}

rt

2024/5/31 15:09
加载中...