超时???????????

null him 2020-10-29 21:07:16 2020-10-29 21:09:52 4
#include<iostream>
using namespace std;
bool ph(int x){
	for(int i=2;i<x;i++){
		if(x%i==0){
			return 0;
		}
	}
	return 1;
}
int main(){
	int a;
	cin>>a;
	if(ph(a)){
		cout<<"yes";
	}
	else{
		cout<<"no";
	}
	return 0;
} 
{{ vote && vote.total.up }}

共 1 条回复

root 站长

i 从 2 循环到 n 肯定超时了,你用 i * i <= x 代替 i < x 试试!