Fzu 1563 prime numbers

Source: Internet
Author: User
Accept: 332 submit: 1218
Time Limit: 1000 msec memory limit: 32768 kb problem descriptioncompute the number of prime numbers in a given interval.

A prime number is an integer p greater than 1 whose only positive divisors are 1 and P.

Inputthe first line contains the number of test cases T (t <= 1000 ).

Each test case contains a single line with two numbers separated by a single space: A and B, 2 <= A <= B <= 1000000.

Outputfor each test case output a single line, containing the number of primes between A and B random Sive. sample input2 2 7 3 1000000 sample output4 78497 // note range (1-1000000) // unexpected solution, so that the foj Runtime is about S ,,..... // if you want to leave a message in a good way, thank you. # Include <iostream> <br/> # include <cmath> <br/> using namespace STD; <br/> const int max = 1000000; <br/> bool isprime [Max + 1]; <br/> int prime [Max]; <br/> int pnum; <br/> void getprime () <br/>{< br/> int I, j; <br/> memset (isprime, 0, sizeof (isprime); <br/> pnum = 0; <br/> for (I = 2; I <= max; I ++) <br/>{< br/> If (! Isprime [I]) prime [pnum ++] = I; <br/> for (j = 0; j <pnum & prime [J] * I <= max; j ++) <br/>{< br/> isprime [prime [J] * I] = 1; <br/> if (I % prime [J] = 0) break; <br/>}< br/> int main () <br/>{< br/> int N, A, B, count, I; <br/> getprime (); <br/> while (scanf ("% d", & N )! = EOF) <br/>{< br/> while (n --) <br/>{< br/> COUNT = 0; <br/> scanf ("% d", & A, & B); <br/> for (I = A; I <= B; I ++) <br/> If (isprime [I] = 0) <br/> count ++; <br/> printf ("% d/N", count ); <br/>}< br/> return 0; <br/>}

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.