Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
120886 | 鲁博睿 | 判断质数(使用while循环) | C++ | Time Limit Exceeded | 1000 MS | 264 KB | 447 | 2025-06-01 15:50:15 |
#include <bits/stdc++.h> ? #include<cmath>//数学头文件 using namespace std; int main() { int n; int flag=1; //提前假设 cin>>n; int i=2; //验证假设 while(i<=sqrt(n)){ //缩短遍历范围,提高程序速度 if(n%i==0){ //存在其他因子 flag = 0; //假设不成立 break; } } //输出结果 if(flag==1){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } return 0; }