HduOJ 2162 - Primes
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2161
题意:判断n是不是素数,输入到0停止。题目规定1 2 都不是素数。
题解:筛素数。老题目。不过这次是普通筛23333.。之前做的题了。
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
#define N 16001
bool prime[N];
void init(){
for(int i = ; i <= N ; i++){
prime[i] = true;
} for(int i = ; i < N; i++){
int tot = (i + ) / ;
for(int j = ; j <= tot; j++){
if(i % j == ){
prime[i] = false;
break;
}
}
}
prime[] = false;
prime[] = false; }
int main(){
init();
int n;
int cas = ;
while(scanf("%d",&n) , n>){
printf("%d: ",cas++);
if(prime[n])
printf("yes\n");
else
printf("no\n");
}
return ;
}
HduOJ 2162 - Primes的更多相关文章
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...
- [LeetCode] Count Primes 质数的个数
Description: Count the number of prime numbers less than a non-negative number, n click to show more ...
- hduoj 1455 && uva 243 E - Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1455 http://uva.onlinejudge.org/index.php?option=com_onlin ...
- projecteuler Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two milli ...
- leetcode-Count Primes 以及python的小特性
题目大家都非常熟悉,求小于n的所有素数的个数. 自己写的python 代码老是通不过时间门槛,无奈去看了看大家写的code.下面是我看到的投票最高的code: class Solution: # @p ...
- Count Primes - LeetCode
examination questions Description: Count the number of prime numbers less than a non-negative number ...
- [leetcode] Count Primes
Count Primes Description: Count the number of prime numbers less than a non-negative number, n click ...
- Count Primes
Count the number of prime numbers less than a non-negative number, n public int countPrimes(int n) { ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
随机推荐
- 训练集(train set) 验证集(validation set) 测试集(test set)。
训练集(train set) 验证集(validation set) 测试集(test set). http://blog.sina.com.cn/s/blog_4d2f6cf201000cjx.ht ...
- 无法将 Ethernet0 连接到虚拟网络”VMnet0″ 详细信息可以在 vmware.log 文件中找到未能连接虚拟机Ethernet0
在 vmware“编辑->虚拟网络设置”里面,点“恢复默认”可解决.
- Mysql DBA
1 mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when dumping table `tb_co ...
- Apriori-关联规则挖掘算法
Apriori算法采用的是自底向上的方法,从1-频繁集开始,逐步找出高阶频繁集. 它的基本流程是:第一次扫描交易数据库D时,产生1- 频繁集.在此基础上经过连接.修剪产生2-频繁集.以此类推,直到无法 ...
- 上线出现[x86_64, i386]
echo "Target architectures: $ARCHS" APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}&quo ...
- 2018-2-13-win10-uwp-让焦点在点击在页面空白处时回到textbox中
title author date CreateTime categories win10 uwp 让焦点在点击在页面空白处时回到textbox中 lindexi 2018-2-13 17:23:3 ...
- 检测apache状态,当apache处于非running状态如何脚本启动
编写脚本内容 #!/bin/bashURL="http://127.0.0.1/"curlit(){curl --connect-timeout 15 --max-time 20 ...
- CF755G PolandBall and Many Other Balls/soj 57送饮料
题意:长度为n的序列,相邻两个或单独一个可以划分到一个组,每个元素最多处于一个组. 问恰好分割成k(1<=k<=m)段有多少种方案? 标程: #include<bits/stdc++ ...
- 阿里云重磅推出物联网设备身份认证Link ID²
2018年12月19日,阿里云宣布推出新版物联网设备身份认证Link ID²及物联网安全运营中心Link SOC,护航万物智联. 随着越来越多的设备连接到网络中,随之而来的安全问题越来越突出. ...
- PHP ftp_site() 函数
定义和用法 The ftp_site() 函数向 FTP 服务器发送 SITE 命令. SITE 命令没有标准化,在不同的服务器上不尽相同.对于处理文件权限或组关系方面的事情,SITE 命令很有用. ...