Generation

generate functionWed, 16 Nov 2022

A high school has 100 students and 100 lockers. On the first day of school, the principal plays the following game: She asks the first student to go and open all the lockers. She then asks the second student to go and close all the even- numbered lockers. The third student is asked to check every third locker. If it is open, the student closes it; if it is closed, the student opens it. The fourth student is asked to check every fourth locker. If it is open, the student closes it; if it is closed, the student opens it. The remaining students continue this game. In general, the nth student checks every nth locker. If the locker is open, the student closes it; if it is closed, the student opens it. After all the students have taken their turn, some of the lockers are open and some are closed. Your job now, is to write a function named “mostTouchableLocker()” which takes two input parameters i.e number_of_lockers and number_of_students that returns the locker number which is touched by the most of the students. If you have more than one lockers that are most touched. Let say locker 1 and 2 both are most touchable, then your function should return 2

++ int mostTouchableLocker(int numberOfLockers, int numberOfStudents) { // TODO: implement your solution here } // test case mostTouchableLocker(100, 100) # 2 mostTouchableLocker(10, 10) # 2 mostTouchableLocker(1000, 1000) # 3

Questions about programming?Chat with your personal AI assistant