Canadian Computing Competition: 2004 Stage 1, Junior #2
In CS City, a mathematical place to live, the mayor is elected every 4 years, the treasurer is appointed every 2 years, the chief programmer is elected every 3 years and the dog-catcher is replaced every 5 years.
This year, Year , the newly elected mayor announced the appointment of the
new treasurer, a new dog-catcher and congratulated the chief programmer for
winning the recent election. That is, all positions were changed over. This is
highly unusual. You will quantify how unusual this really is.
Write a program that inputs the year and the future year
and lists all
years between
and
inclusive when all positions change.
Sample Input
2004
2100
Sample Output
All positions change in year 2004
All positions change in year 2064
Comments
Ahh whats wrong with my code :(
I found your problem. For example, let's say X = 2000 and Y = 2124. Your output would output 2000 and 2060 correctly, but not after that since you're not updating the value of X anywhere. However, by changing the value of X, the for loop would be messed up due to X not being a constant and is present in the loop. I suggest you use a while loop instead.
wait, does the start of the range is always all pos change?
Of course. It's written in the question. It says that since the new mayor just won the elect, he changed all of the positions
What's wrong with my code? I tried different cases on my computer and their all correct.
Re-read the sample output. Outputting just the year is not correct.
This comment is hidden due to too much negative feedback. Show it anyway.
Your solution only checks up to year Y - 1.
it worked bro tnx very much
The mayor every 4, the treasurer every 2, the chief programmer every 3, and the dog-catcher every 5 years. How many years does it take for all of them to change at the same time? Think very carefully.
First get their LCM which is 60 you might think its thirty... but is it a multiple of four? lol 4, 8, 12, 16, 20, 24, 28, 32... 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 ... 3, 6, 9, 12, 15, 18, 21, 24, 27, 30... 5, 10, 15, 20, 25, 30...