为为为为什么会错(20分求教)
查看原帖
为为为为什么会错(20分求教)
1372344
ZJY1207楼主2024/8/25 22:31
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,n;
	cin>>a>>n;
	for(int i=0;i<n;i++){
		int k;
		cin>>k;
		double x;
		x=sqrt(k);
		if(x-int(x)==0&&k>=a){
			cout<<"lucky"<<endl;
		} else{
			bool f1=false;
			for(int j=sqrt(a);j*j<=k;j++){
				if(k%(j*j)==0){
					f1=true;
					break;
				}
			}
			if(f1){
				cout<<"lucky"<<endl;
			}else{
				if(k<a){
					k=a;
				}
				while(true){
					bool y=false;
					x=sqrt(k);
					if(x-int(x)==0){
						cout<<k<<endl;
						break;
					} else{
						for(int j=2;j*j<k;j++){
							if(k%(j*j)==0){
								cout<<k<<endl;
								y=true;
								break;
							}
						}
					}
					if(y){
						break;
					}
					k++;
				}
			}
		}
	}
}

QAQ

2024/8/25 22:31
加载中...