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 有疑问?点这里 ...
随机推荐
- .gitignore 文件使用说明
我们在使用 Git 进行版本控制的时候,有些文件是无需纳入 Git 管理的,通常都是些自动 生成的文件,像日志或者编译过程中创建的文件.我们可以创建一个名为 .gitignore 的文件,列出要忽略的 ...
- RabbitMQ使用(二)
1.消息确认消费 1. 生产者端发消息时,加参数 properties=pika.BasicProperties( delivery_mode=2, # make message persistent ...
- 使用Jedis操作Redis-使用Java语言在客户端操作---set类型
原文地址:http://www.cnblogs.com/lixianyuan-org/p/9509696.html 1 //测试set数据类型 2 /** 3 * 在Redis中,我们可以将Set类型 ...
- 9、TestNG介绍与安装
介绍 TestNG是一个受JUnit和NUnit启发的测试框架,但引入了一些新功能,使其更加强大和易于使用,例如: 注释. 在任意大的线程池中运行你的测试,这些线程池有各种可用的策略(所有方法在他们自 ...
- shell 生成多级目录遇到最后一级目录乱码 mkdir -p a/b/c/d
使用shell完成从配置文件中获取路径(字符匹配),在生成多级路径的过程过遇到最后一级目录乱码. 代码如下: mkdir -p $path 这个$path是从配置文件中读取. 如何解决: 1.检查是否 ...
- Django框架(十三)—— Djang与Ajax
目录 Djang与Ajax 一.什么是Ajax 二.Ajax的特点 1.异步 2.局部刷新 三.Ajax优点 四. 基于jquery的Ajax使用 1.基本语法 2.完整使用语法 3.利用ajax提交 ...
- 不走弯路,微信小程序的快速入门?
微信小程序下载注册地址:https://mp.weixin.qq.com/cgi-bin/wx 微信小程序登开发者平台地址(可以查看小程序APPID):https://mp.weixin.qq.com ...
- HttpURLConnection模拟登录学校的正方教务系统
教务系统登录界面 如图1-1 1-1 F12-->network查看登录教务系统需要参数: __VIEWSTAT txtUserName TextBox2 txtSecretCode Radio ...
- Spring接收数据,传递数据
Spring接收数据,传递数据 前提配置 POM <dependency> <groupId>org.springframework</groupId> < ...
- android是32-bit系统还是64-bit系统
转自:http://www.cnblogs.com/pengwang/archive/2013/03/11/2954496.html 电脑CPU分32位和64位,这个我们都知道.用了这么长时间的and ...