1152: 是否是素数

https://neooj.com:8082/oldoj/problem.php?id=1152

题目描述

写一个判断素数的函数,在主函数输入一个整数,输出是否是素数的消息。

输入

一个数

输出

如果是素数输出prime 如果不是输出not prime

样例输入

97

样例输出

prime
 
判素数是很常用的技巧,尤其是后面学到数论之后会对一些知识点起到启发性作用。
AC CODE:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int prime(int x)
{
for(int i=;i<=sqrt(x);i++)
if(x%i==)
return ;
return ;
}
int main()
{
int n,hahaha;
scanf("%d",&n);
hahaha = prime(n);
if(hahaha==)
printf("not prime");
else
printf("prime");
return ;
}

最新文章

  1. sql 删除表中的重复记录
  2. delete
  3. NOIP主要考查范围
  4. asp.net中当点击按钮时出现grid编辑弹框
  5. win7(X64)系统下cuda7.5和VS2013的配置
  6. ASP.NET的SEO:基础知识
  7. opensuse 安装 Anaconda3 之后出现Could not start d-bus. Can you call qdbus?
  8. SQL SERVER安装提示“安装了 Microsoft Visual Studio 2008 的早期版本
  9. hadoop数据流转过程分析
  10. Swift - 41 - swift1.2新特性(1)
  11. Ruby入门--Linux/Windows下的安装、代码开发及Rails实战
  12. STM32F407的串口采用DMA收发数据
  13. apache用户认证,ssl双向认证配置
  14. python入门之函数
  15. ftp服务器的简单配置使用
  16. php中heredoc与nowdoc的使用方法
  17. tomcat 修改默认字符集
  18. Angular 自定义拖拽指令
  19. 页面中dropDownListt的二级关联
  20. Web常见安全漏洞-SQL注入

热门文章

  1. FFT_应用和例题
  2. vue.js 使用v-model v-once
  3. Win10中SVN图标不显示的解决
  4. Paper | Dynamic Residual Dense Network for Image Denoising
  5. 【SpringCloud之pigx框架学习之路 】2.部署环境
  6. Python连载34-信息队列
  7. HTML+css基础 css的几种形式
  8. Practical Go: Real world advice for writing maintainable Go programs
  9. webstorm关闭烦人的eslint语法检查
  10. NoNodeAvailableException[None of the configured nodes are available:[.127.0.0.1}{127.0.0.1:9300]