60pts求调
查看原帖
60pts求调
1183074
xzy_AK_IOI楼主2024/9/30 21:26
#include<bits/stdc++.h>
using namespace std;
string s,shu;
int ans;
int string_int(string m){
	int sum=0;
	for (char i:m){
		sum=sum*10+(i-'0');
	}
	return sum;
}
bool prime(int r){
	if (r<2) return 0;
	for (int i=2;i<=sqrt(r);i++){
		if (r%i==0) return 0;
	}
	return 1;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout<<"Enter the number=\n";
	while (cin>>s,s!="you"){
		shu="";
		for (char i:s){
			if (i>='0' && i<='9') shu+=i;
		}
		if (shu=="") {
			continue;
		}
		if (shu.size()>8){
			cout<<"Prime? No!\nThe number is too large!\n\n";
			cout<<"Enter the number=\n";
			continue;
		}
		int k=string_int(shu);
		if (k>40000000){
			cout<<"Prime? No!\nThe number is too large!\n\n";
			cout<<"Enter the number=\n";
			continue;
		}
		if (prime(k)){
			cout<<"Prime? Yes!\n\n";
			cout<<"Enter the number=\n";
			continue;
		}
		if (k==1){
			cout<<"Prime? No!\n\n";
			cout<<"Enter the number=\n";
			continue;
		}
		cout<<"Prime? No!\n"<<k<<'=';
		int p=k;
		for (int i=2;i<=p;i++){
			ans=0;
			while (k && k%i==0){
				ans++;
				k/=i;
			}
			if (!ans) continue;
			cout<<i<<'^'<<ans;
			if (k!=1) cout<<'*';
		}
		cout<<"\n\n";
		cout<<"Enter the number=\n";
	}
    return 0;
}
2024/9/30 21:26
加载中...