PrimesTime
limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 7659 Accepted Submission (s): 3130
Problem Descriptionwrite A program to the read in a list of integers and determine whether or not each number is prime. A number, N, is prime if it only divisors be 1 and N. For this problem, the numbers 1 and 2 is not considered primes.
Inputeach input line contains a single integer. The list of integers is terminated with a number<= 0. Assume that the input contains at most of numbers and each number are less than or equal to 16000.
Outputthe 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
12345170
Sample Output
1:no2:no3:yes4:no5:yes6:yes
There's nothing to say about the code:
#include <stdio.h> #define MAX 16100bool Notprime[max]; int main () {for (int i = 2; i < MAX; ++i) {for (int j = 2; j *i < MAX; ++J) {Notprime[i*j] = true;}} NOTPRIME[1] = notprime[2] = true; int n, C=1;while (~scanf ("%d", &n) && n>0) {printf ("%d:", C + +); if (!notprim E[n]) {puts ("yes");} Else{puts ("No");}} return 0;}
with June
Hdu 2161 Primes Sieve method for solving the problem of prime number flood