首页 > 试题广场 >

素数判定

[编程题]素数判定
  • 热度指数:19631 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
给定一个数n,要求判断其是否为素数(0,1,负数都是非素数)。

输入描述:
测试数据有多组,每组输入一个数n。


输出描述:
对于每组输入,若是素数则输出yes,否则输入no。
示例1

输入

13

输出

yes
头像 牛客652687585号
发表于 2022-03-04 19:43:34
#include<iostream> #include<cstdio> #include<cmath> using namespace std; bool Judge(int n){    &n 展开全文
头像 准备笔试的哈士奇很坦荡
发表于 2023-03-20 20:40:47
#include <stdio.h> #include <math.h> int main() { int n; scanf("%d",&n); if(n<=1){ printf("no\n"); return 0 展开全文
头像 友人帐在逃妖怪
发表于 2021-02-21 10:42:42
//素数判定 #include <iostream> #include <cstdio> #include <cmath> using namespace std; bool Judge(int n) { if (n < 2) { retu 展开全文
头像 土尔逊Torson
发表于 2023-05-08 22:52:17
//土尔逊Torson 编写于2023/5/08 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <math.h> using namespace st 展开全文
头像 着力登峰
发表于 2023-08-11 10:00:48
#include<iostream> #include<cmath> using namespace std; //例题6.7 素数判定 int isPrime(int num) { if (num == 1) { return 0; } 展开全文
头像 ChaChaCharis
发表于 2023-03-06 15:02:30
#include <cstdio> #include <cmath> using namespace std; int main(){ int n; bool flag=true; while( scanf("%d",&n)!=EOF){ if 展开全文
头像 Huster水仙
发表于 2023-01-14 20:56:30
暴力枚举法 #include<iostream> using namespace std; bool baoli(int x){ if(x<=1)return false; for(int i=2;i*i<=x;i++){ if(x%i==0) 展开全文
头像 牛客568792594号
发表于 2024-02-16 21:50:06
#include <bits/stdc++.h> using namespace std; bool is_prime(int x){ if (x <= 1) return false; for (int i=2; i<=x/i; i++){ if (x % i 展开全文
头像 给我就亿下
发表于 2023-03-19 16:54:12
#include <iostream> #include <cmath> using namespace std; bool isPrim (int n){ if (n == 0 || n == 1){ return false; }else{ for (in 展开全文
头像 bigbigcake
发表于 2024-03-09 09:38:57
#include <cmath> #include <iostream> using namespace std; int main() { int n; while(cin>>n){ bool isPrime = true; 展开全文

问题信息

难度:
88条回答 9044浏览

热门推荐

通过挑战的用户

查看代码