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)