Hdu 2161 Primes Sieve method for solving the problem of prime number flood

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.