University of Lethbridge - Mathematics & Computer Science

Problem #1 An Open and Shut Case

A new high school has just been opened which has a maximum capacity of 2000 students. The school has one locker for each of the N students enrolled. On the first day of classes the students will enter the school one at a time. The first student to enter will open all the lockers. The second student to enter will shut every other locker starting with the second locker. The third student to enter will change every third locker starting with locker number three. The fourth changes every fourth locker starting with the fourth one. So on for all N students. Changing a locker means opening it if it is closed, or shutting it if it is open. After all the students have entered, print a listing of the lockers showing which are open and which are shut.

Input: From the file open.dat will be a list of positive integers, N.

Output: To the file open.out. An N character string of 'O's and 'S's showing the final status of the lockers, where the first character corresponds to the first locker, and O means open and S means shut. There will be one line of output for each N read.

For example, if the input file is

5 3 4
then the output file would be
OSSOS
OSS
OSSO


Original problem: Rocky Mountain Region ACM contest, 1993