14 solutions
-
-6
解题报告
撰写人: Jacy
题意分析
质数是指在大于 1 的自然数中,除了 1 和它本身以外不再有其他因数的自然数。现在需要编写一个程序,判断输入的数是否为质数。
输入格式 一个整数n,其中2≤n≤1000000。
输出格式 如果n是质数,输出 "Yes";否则输出 "No"。
难度等级
★☆☆☆☆
解题思路
用for循环判断n的因子是否能被n整除,如果是则输出no终止程序,若不是则输出yes
解题反思
无
参考程序
#include<bits/stdc++.h> using namespace std; int n; int main() { cin>>n; for(int i=2;i<n;i++) if(n%i==0){ cout<<"No"; return 0; } cout<<"Yes"; return 0; }
Information
- ID
- 602
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 1
- Tags
- (None)
- # Submissions
- 51
- Accepted
- 39
- Uploaded By