题目链接

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. 判断素数 【水】的更多相关文章

  1. PAT 天梯赛 L1-047. 装睡 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-047 AC代码 #include <iostream> #include <cstdio&g ...

  2. PAT 天梯赛 L1-042. 日期格式化 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-042 AC代码 #include <iostream> #include <cstdio&g ...

  3. PAT 天梯赛 L1-041. 寻找250 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-041 AC代码 #include <iostream> #include <cstdio&g ...

  4. PAT 天梯赛 L1-022. 奇偶分家 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-022 AC代码 #include <iostream> #include <cstdio&g ...

  5. PAT 天梯赛 L1-016. 查验身份证 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-016 AC代码 #include <iostream> #include <cstdio&g ...

  6. PAT 天梯赛 L1-014. 简单题 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-014 AC代码 #include <iostream> #include <cstdio&g ...

  7. PAT 天梯赛 L1-012. 计算指数 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-012 AC代码 #include <iostream> #include <cstdio&g ...

  8. PAT 天梯赛 L1-010. 比较大小 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-010 AC代码 #include <iostream> #include <cstdio&g ...

  9. PAT 天梯赛 L1-007. 念数字 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-007 AC代码 #include <iostream> #include <cstdio&g ...

  10. PAT 天梯赛 L1-004. 计算摄氏温度 【水】

    题目链接 https://www.patest.cn/contests/gplt/L1-004 AC代码 #include <iostream> #include <cstdio&g ...

随机推荐

  1. css中div标签不置顶

    设置div属性垂直对齐方式为:top <div style="vertical-align: top;"></div>

  2. 学习spring in action 第一天

    这段时间,开始学习java吧,因为C sharp 学习了java的大量语法格式,所以,留意下,就不会错了,java 有的c sharp也有,而且之前我也学习过java的桌面开发,但是一下子上来就要自己 ...

  3. 使用httpClient发送get\post请求

    maven依赖 <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId&g ...

  4. 测试ssh框架中hibernate的事务

    <!-- 配置切面 --> <aop:config> <aop:pointcut expression="execution(* com.xxx.lobs.ma ...

  5. PHP基础之Autoload

    PHP的自动加载autoload机制很重要,这里做2个小练习 原创文章,转载请注明:http://www.cnblogs.com/phpgcs 文件结构如下,2种方式实现自动加载 1,自定义函数 2, ...

  6. UTF-8和GBK的区别

    GBK是在国家标准GB2312基础上扩容后兼容GB2312的标准(好像还不是国家标准).GBK编码专门用来解决中文编码的,是双字节的.不论中英文都是双字节的. UTF-8编码是用以解决国际上字符的一种 ...

  7. 【转】在Eclipse中使用JUnit4进行单元测试(初级篇)

    http://www.builder.com.cn/2007/0901/482336.shtml 首先,我们来一个傻瓜式速成教程,不要问为什么,Follow Me,先来体验一下单元测试的快感! 首先新 ...

  8. SVD分解的c++代码(Eigen 库)

    使用Eigen 库:进行svd分解,形如 A = U * S * VT. JacobiSVD<MatrixXd> svd(J, ComputeThinU | ComputeThinV); ...

  9. PowerDesigner 建模后如何导入到数据库

    from:https://jingyan.baidu.com/article/7f766daf465e9c4101e1d0d5.html 大家都知道PowerDesigner是一个数据库建模工具,但是 ...

  10. Android记住password后自己主动登录

    /**  *   * @author alex  * @version 2014-7-31下午5:25:45  *  */ public class LoginActivity extends Act ...