Along a single row of an orchard, trees are numbered 1 through n in planting order. As the foreman walks the row, at every tree number divisible by 3 the crew shouts "Prune"; at every tree number divisible by 5 they shout "Water"; at every tree number divisible by both 3 and 5 they shout "PruneWater" (prune first, then water, concatenated with no space or separator); and at every other tree they simply call out its position number as a plain decimal integer. Produce the full sequence of calls for trees 1 through n, in order, one call per line.
A single line containing one integer n.
n lines. Line i (for i from 1 to n) contains the call for tree i, exactly as described above.
Example 1
Input
5
Expected
1 2 Prune 4 Water
Explanation
Trees 1 and 2 are divisible by neither 3 nor 5, so they print their own numbers. Tree 3 is divisible by 3 only, so it prints "Prune". Tree 4 prints its own number. Tree 5 is divisible by 5 only, so it prints "Water".
Example 2
Input
15
Expected
1 2 Prune 4 Water Prune 7 8 Prune Water 11 Prune 13 14 PruneWater
Explanation
Trees 3, 6, 9, and 12 are divisible by 3 only and print "Prune"; trees 5 and 10 are divisible by 5 only and print "Water"; tree 15 is divisible by both 3 and 5 and prints "PruneWater"; every other tree from 1 to 14 prints its own number.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →