HDU 2161 数学
2015-11-06 15:33
363 查看
Primes
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 9434 Accepted Submission(s): 3954
Problem Description
Write a program to read in a list of integers and determine whether or not each number is prime. A number, n, is prime if its only divisors are 1 and n. For this problem, the numbers 1 and 2 are not considered primes.
Input
Each input line contains a single integer. The list of integers is terminated with a number<= 0. You may assume that the input contains at most 250 numbers and each number is less than or equal to 16000.
Output
The output should consists of one line for every number, where each line first lists the problem number, followed by a colon and space, followed by "yes" or "no".
Sample Input
1
2
3
4
5
17
0
Sample Output
1: no
2: no
3: yes
4: no
5: yes
6: yes
开个kuangbin数论的专题
额,很简单的题。题意:输入一个数字,判断这个数字是不是素数,n<=0,结束输入
题解:打素数表就可以了,
(terminated是结束,终止的意思,积累一下单词吧
)
代码:
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; #define N 50000 int prime ; void table_prime() { memset(prime,0,sizeof(prime)); int m=sqrt(N+0.5); for(int i=2;i<=m;i++)if(!prime[i]) for(int j=i*i;j<=N;j+=i)prime[j]=1; prime[1]=prime[2]=1; } int main() { table_prime(); int n,cas=0; while(~scanf("%d",&n)) { if(n<=0)break; else { printf("%d: %s\n",++cas,!prime ?"yes":"no"); } } return 0; }
相关文章推荐
- 搬迁学习笔记1——Handler的基本使用、子线程更新UI的方式
- C语言:存取结构体成员的点运算符(.)和箭头运算符(->)的区别
- Android编程实现图片的浏览、缩放、拖动和自动居中效果
- Mac系统怎么上谷歌
- 使用Genymotion模拟器的搭建
- lua调用syslog; 使用C注册lua方法
- Hibernate映射实体类时解决没有ID的问题
- UVALive 4670 Dominating Patterns
- fh admin bootstrap 模版下载 框架 源码 SpringMVC mybatis or hibernate
- json对象在java和javascript中的遍历
- MSSQL 排序函数
- 使用Eclipse中提供的Refactor(重构)工具
- spring @ExceptionHandler注解方式实现异常统一处理
- Verilog同步FIFO
- svn: Can't revert without reverting parent
- Quartz(GUI)图形界面程序----Quartz Web
- File.ReadAllText 读取中文乱码问题
- Android开发——通过扫描二维码,打开或者下载Android应用
- Java语言基础之Object类
- LayoutInflater