Blue Bridge Cup-lucky number (play table)

Source: Internet
Author: User

Previous questions lucky number time limit: 1.0s memory limit: 256.0MBProblem description

The lucky number is named by the Polish mathematician Ulam. It is generated using a "sieve method" similar to the number of primes generated

First write the natural number 1,2,3,4,5,6,.... starting from 1

1 is the first lucky number.

We start with the number 2. Delete all items that are divisible by 2 to:

1_3_5_7_9....

Tighten them up and re-order them:

1 3 5 7 9 ..... At this point, the 3 is the 2nd lucky number, and then the number of all can be divisible by 3 ordinal position to delete. Note that is the ordinal position, not the number itself can be divisible by 3!! The deletion should be 5, 11, 17, ...

At this point 7 is the 3rd lucky number, and then delete the ordinal position can be divisible by 7 (19,39,...)

The last remaining sequence is similar to the following:

1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75, 79, ...

Input format enter two positive integers m n, separated by spaces (M < n < 1000*1000) output format program outputs the number of lucky numbers between M and N (not including M and N). Sample Input 11 20 Sample Output 15 Sample Input 230 69 sample output 28




Thinking: is a little bit of skill to play the table, but this data is not very weak ah, my original code will time out, the result of the table has been changed to a small, and then put it here


AC Code:
















Blue Bridge Cup-lucky number (play table)

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.