90分求助!!!
查看原帖
90分求助!!!
952047
yellow_cloud楼主2024/7/27 19:13
#include<bits/stdc++.h>
using namespace std;
int n1,n2,m=0;
bool f(int t){
	if(t<2){
		return 0;
	}
	for(int i=2;i<t;i++){
		if(t%i==0){
			return 0;
		}
	}
	m++;
	return 1;
}
int main(){
	cin>>n1>>n2;
	for(int i=n1;i<n2;i++){
		if(f(i)==1){
			cout<<i<<",";
		}else{
			for(int j=i-1;j>=1;j--){
				if(i%j==0&&f(j)==1){
					cout<<j<<",";
					break;
				}
			}
		}
	}
	if(f(n2)==1){
		cout<<n2<<",";
	}else{
		for(int j=n2-1;j>=1;j--){
			if(n2%j==0&&f(j)==1){
				cout<<j;
				break;
			}
		}
	}
	
	return 0;
}
2024/7/27 19:13
加载中...