14 solutions
-
-1
解题报告: 撰写人:李秉霖 题意分析: 这是一道简单的判断输入的数是否为质数的程序 难度等级: ★☆☆☆☆ 解题思路: 先利用bool类型然后再判断就可以了。 解题反思: 循环要从2开始 参考程序: #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; bool isPrime=true; for(int i=2;i*i<=n; i++){ if(n % i == 0){ isPrime=false; break; } } if(isPrime){ cout<<"Yes"<<endl; }else{ cout<<"No"<<endl; } return 0; }
Information
- ID
- 602
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 1
- Tags
- (None)
- # Submissions
- 51
- Accepted
- 39
- Uploaded By