school has 100 lockers and 100 students. All lockers areclosed on the first day of school. As the students enter, the first student, denotedas S1, opens every locker. Then the second student, S2, begins with the secondlocker, denoted as L2, and closes every other locker. Student S3 begins with thethird locker and changes every third locker (closes it if it was open and opens it ifit was closed). Student S4 begins with locker L4 and changes every fourth locker.Student S5 starts with L5 and changes every fifth locker, and so on, until studentS100 changes L100.After all the students have passed through the building and changed the lockers,which lockers are open? Write a program to find your answer and display all openlocker numbers separated by exactly one space.

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter18: Deterministic Dynamic Programming
Section18.1: Two Puzzles
Problem 2P
icon
Related questions
icon
Concept explainers
Question

school has 100 lockers and 100 students. All lockers are
closed on the first day of school. As the students enter, the first student, denoted
as S1, opens every locker. Then the second student, S2, begins with the second
locker, denoted as L2, and closes every other locker. Student S3 begins with the
third locker and changes every third locker (closes it if it was open and opens it if
it was closed). Student S4 begins with locker L4 and changes every fourth locker.
Student S5 starts with L5 and changes every fifth locker, and so on, until student
S100 changes L100.
After all the students have passed through the building and changed the lockers,
which lockers are open? Write a program to find your answer and display all open
locker numbers separated by exactly one space.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage