您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: