60求调
查看原帖
60求调
838265
hostangelb楼主2024/11/25 22:05
#include <bits/stdc++.h>

using namespace std;
int x;
bool check(string s)
{
	int cnt = 0;
	for (int i = 0; i < s.size(); ++i)
	{
		if (s[i] >= '0' && s[i] <= '9') x = x * 10 + s[i] - '0', ++cnt;
	}
	if (!cnt) return false;
	return true;
}
bool isPrime(int x)
{
	if (x < 2) return false;
	for (int i = 2; i * i <= x; ++i)
	{
		if (x % i == 0) return false;
	}
	return true;
}
void fact()
{
	cout << "Prime? ";
	if (isPrime(x)) 
	{
		cout << "Yes!";
		if (x > 40000000) cout << "The number is too large!";
		cout << "\n\n";
		return;
	}
	cout << "No!\n";
	if (x > 40000000) 
	{
		cout << "The number is too large!\n\n";
		return;
	}
	if (x < 2)
	{
		cout << "\n\n";
		return;
	}
	cout << x << '=';
	int cnt10 = 0;
	for (int i = 2; i <= x; ++i)
	{
		int cnt = 0;
		while (x % i == 0)
		{
			x /= i, ++cnt;
		}
		if (cnt10 && cnt) cout << '*';
		if (cnt)
		{
			cout << i << "^" << cnt;
			++cnt10;
		}
	}
	cout << "\n\n";
}
int main()
{
    while (cout << "Enter the number=\n")
    {
    	x = 0;
    	string s;
    	getline(cin, s);
    	if (!check(s)) break;
    	fact();
	}
    return 0;
}
2024/11/25 22:05
加载中...