The lucky number is the sequence number generated by the filter algorithm: if the number in the series of positive numbers survives the filter algorithm, it gets lucky and survives, otherwise it disappears in sequ First you have to find a series of numbers, from 1 to the required size. The first number is 1 and it survives: next to it there is the number 2, which becomes the filter: each second number in the list (counts from 1) must be sorted (as it says every equal number). After this step, the next number to survive after 1 is 3: subtract every third number from the list (count from 1). After this step, the next number to survive after 3 is 7: remove the whole number seven from the list. Repeat steps to increase the filter status for all steps (as if a new step filter filter is equal to the first number larger than the previous step the last lucky number) until no numbers are removed from the list. See the example below for the given size = 25 and nth = 5. Step 1: Generate a list from 1 to size. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 Step 2: First filter 2: Every second number from the beginning should be deleted. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 Step 3: Sieve filter now 3: every third number from the beginning should be deleted. 1, 3, 5, 7,9, 11, 13, 15, 17, 19, 21, 23, 25 Step 4: The filter filter is now 7: Every seventh number from the beginning must be deleted. 1, 3, 7, 9, 13, 15, 19, 21, 25 Step 5: Sieve filter is now 9: each ninth number should be deleted, but our list now contains only 8 numbers so the algorithm ends. The nth number sequence is 13. Since size is the size of the same initial member, write a function that returns the nth number of sequences resulting after the filtering process. Examples getluckyNumber (25, 5) - 13 // The same set and procedure as an example in the instructions above. getluckyNumber (3, 2) 3 // Original set = 1, 2, 3 // After the first step = 1, 3 // No more possible steps (filter is third part, set length is 2) // The second part (nth) is 3 getluckyNumber (120, 13) - 49

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

JAVA Programming

The lucky number is the sequence number generated by the filter algorithm: if the number in the series of positive numbers survives the filter algorithm, it gets lucky and survives, otherwise it disappears in sequence.
First you have to find a series of numbers, from 1 to the required size.
The first number is 1 and it survives: next to it there is the number 2, which becomes the filter: each second number in the list (counts from 1) must be sorted (as it says every equal number).
After this step, the next number to survive after 1 is 3: subtract every third number from the list (count from 1).
After this step, the next number to survive after 3 is 7: remove the whole number seven from the list.
Repeat steps to increase the filter status for all steps (as if a new step filter filter is equal to the first number larger than the previous step the last lucky number) until no numbers are removed from the list.
See the example below for the given size
= 25 and nth = 5.
Step 1: Generate a list from 1 to size.
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
Step 2: First filter 2: Every second number from the beginning should be deleted.
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
Step 3: Sieve filter now 3: every third number from the beginning should be deleted.
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25
Step 4: The filter filter is now 7: Every seventh number from the beginning must be deleted.
1, 3, 7, 9, 13, 15, 19, 21, 25
Step 5: Sieve filter is now 9: each ninth number should be deleted, but our list now contains only 8 numbers so the algorithm ends. The nth number sequence is 13.
Since size is the size of the same initial member, write a function that returns the nth number of sequences resulting after the filtering process.
Examples
getluckyNumber (25, 5) → 13
// The same set and procedure as an example in the instructions above.
getluckyNumber (3, 2) – 3
// Original set
// After the first step
// No more possible steps (filter is third part, set length is 2)
// The second part (nth) is 3
= 1, 2, 3
1, 3
%3D
getluckyNumber (120, 13)
// Same set as in the animated gif in the commands above.
49
Transcribed Image Text:The lucky number is the sequence number generated by the filter algorithm: if the number in the series of positive numbers survives the filter algorithm, it gets lucky and survives, otherwise it disappears in sequence. First you have to find a series of numbers, from 1 to the required size. The first number is 1 and it survives: next to it there is the number 2, which becomes the filter: each second number in the list (counts from 1) must be sorted (as it says every equal number). After this step, the next number to survive after 1 is 3: subtract every third number from the list (count from 1). After this step, the next number to survive after 3 is 7: remove the whole number seven from the list. Repeat steps to increase the filter status for all steps (as if a new step filter filter is equal to the first number larger than the previous step the last lucky number) until no numbers are removed from the list. See the example below for the given size = 25 and nth = 5. Step 1: Generate a list from 1 to size. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 Step 2: First filter 2: Every second number from the beginning should be deleted. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 Step 3: Sieve filter now 3: every third number from the beginning should be deleted. 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25 Step 4: The filter filter is now 7: Every seventh number from the beginning must be deleted. 1, 3, 7, 9, 13, 15, 19, 21, 25 Step 5: Sieve filter is now 9: each ninth number should be deleted, but our list now contains only 8 numbers so the algorithm ends. The nth number sequence is 13. Since size is the size of the same initial member, write a function that returns the nth number of sequences resulting after the filtering process. Examples getluckyNumber (25, 5) → 13 // The same set and procedure as an example in the instructions above. getluckyNumber (3, 2) – 3 // Original set // After the first step // No more possible steps (filter is third part, set length is 2) // The second part (nth) is 3 = 1, 2, 3 1, 3 %3D getluckyNumber (120, 13) // Same set as in the animated gif in the commands above. 49
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY