PAT 天梯赛 L1-028. 判断素数 【水】
题目链接
https://www.patest.cn/contests/gplt/L1-028
AC代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <ctype.h>
#include <numeric>
#include <sstream>
using namespace std;
typedef long long LL;
const double PI = 3.14159265358979323846264338327;
const double E = 2.718281828459;
const double eps = 1e-6;
const int MAXN = 0x3f3f3f3f;
const int MINN = 0xc0c0c0c0;
const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int isPrime(int x){
int flag;
int n,m;
if(x<=1)
flag=0;
else if(x==2||x==3)
flag=1;
else if(x%2==0)
flag=0;
else{
m=sqrt(x)+1;
for(n=3;n<=m;n+=2){
if(x%n==0){
flag=0;
break;
}
else{
flag=1;
}
}
}
return flag;
}
int main()
{
int n;
cin >> n;
int num;
for (int i = 0; i < n; i++)
{
scanf("%d", &num);
if (isPrime(num))
cout << "Yes\n";
else
cout << "No\n";
}
}
PAT 天梯赛 L1-028. 判断素数 【水】的更多相关文章
- PAT 天梯赛 L1-047. 装睡 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-047 AC代码 #include <iostream> #include <cstdio&g ...
- PAT 天梯赛 L1-042. 日期格式化 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-042 AC代码 #include <iostream> #include <cstdio&g ...
- PAT 天梯赛 L1-041. 寻找250 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-041 AC代码 #include <iostream> #include <cstdio&g ...
- PAT 天梯赛 L1-022. 奇偶分家 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-022 AC代码 #include <iostream> #include <cstdio&g ...
- PAT 天梯赛 L1-016. 查验身份证 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-016 AC代码 #include <iostream> #include <cstdio&g ...
- PAT 天梯赛 L1-014. 简单题 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-014 AC代码 #include <iostream> #include <cstdio&g ...
- PAT 天梯赛 L1-012. 计算指数 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-012 AC代码 #include <iostream> #include <cstdio&g ...
- PAT 天梯赛 L1-010. 比较大小 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-010 AC代码 #include <iostream> #include <cstdio&g ...
- PAT 天梯赛 L1-007. 念数字 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-007 AC代码 #include <iostream> #include <cstdio&g ...
- PAT 天梯赛 L1-004. 计算摄氏温度 【水】
题目链接 https://www.patest.cn/contests/gplt/L1-004 AC代码 #include <iostream> #include <cstdio&g ...
随机推荐
- Tree UVA - 548 已知中序遍历和后序遍历,求这颗二叉树。
You are to determine the value of the leaf node in a given binary tree that is the terminal node of ...
- 【Python + ATX】之uiautomator2 PageObject模式自动化框架学习
参考文章: 感谢:cynic (linpengcheng) <ATX 基于 ATX-Server 的 UI 自动化测试框架> <ATX-uiautomator2 实现 webview ...
- Oracle Parallel模式
一.Parallel 1. 用途 强行启用并行度来执行当前SQL.这个在Oracle 9i之后的版本可以使用,之前的版本现在没有环境进行测试.也就是说,加上这个说明,可以强行启用Oracle的多线程处 ...
- OpenCV中Kinect的使用(3)
接OpenCV中Kinect的使用(2),下面内容主要讲述使用OpenNI 控制Kinect 的马达,实现摄像头的上下摆动. 下面是透过OpenNI比较低阶的USB控制介面(XnUSB.h),来做到马 ...
- 图像增强之DDE---基于红外图像的数字图像细节增强DDE
(1)DDE应用背景 (2)DDE算法简介 (3)DDE 实现 (4)DDE 总结和不足 ----------author:pkf -----------------time:2-9 -------- ...
- Mysql中查看每个IP的连接数
) as ip , count(*) from information_schema.processlist group by ip;
- Asp.Net 无刷新文件上传并显示进度条的实现方法及思路
相信通过Asp.Net的服务器控件上传文件在简单不过了,通过AjaxToolkit控件实现上传进度也不是什么难事,为什么还要自己辛辛苦苦来 实现呢?我并不否认”拿来主义“,只是我个人更喜欢凡是求个所以 ...
- 一个智障安装了一天的python和graphlab的血泪史
大概的过程是这样的: 先装了python3.6.1.,然后发现搞错了Σ(  ̄□ ̄||),是32 bit的,卸了重装python 3.6.1 (64bit). 然后装easy_install.pip.i ...
- ios -生成推广海报
#import "ViewController.h" #import "Masonry.h" @interface ViewController () @end ...
- 第四篇:了解 C++ 默默编写并调用的函数
前言 对于一个类来说,最最基础的三类成员函数莫过于:构造函数,析构函数以及拷贝函数 (copy构造函数和=重载函数).即使你的类没有为这些函数做出定义,C++ 也会自动为你创建.本文将讲述的是 C++ ...