Star Arrangements
Time limit1sMemory limit512 MB
Given S stars, list every appealing row pattern a,b where alternating rows of a and b stars use exactly S stars.
- Level
Easy3 of 10
- Topics
- Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
Puerto Rico voted in favor of United States statehood, and flag makers are excited. A flag with 51 stars instead of the current 50 would mean a large jump in flag sales.
The current 50 star pattern is five rows of 6 stars interlaced with four offset rows of 5 stars. The two kinds of rows alternate until every star is placed.
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
In this pattern adjacent rows differ by no more than one star, so the arrangement can be written compactly as the number of stars in the first row and the number in the second row. The pattern above is 6,5.
A 51 star flag with the same property can be three rows of 9 stars interlaced with three rows of 8 stars, written 9,8. If a state were to leave the union instead, seven rows of seven stars, written 7,7, is an appealing arrangement.
A flag pattern is visually appealing when all three conditions below hold.
- Every other row has the same number of stars.
- Adjacent rows differ by no more than one star.
- The first row does not have fewer stars than the second row.
Your team looks past the immediate change to 51 stars and wants to sell flags for any union of three or more states. Given the number of stars to draw on a flag, find every visually appealing arrangement.
Input
The first line contains the number of stars to draw on the flag ().
Output
On the first line, print followed by a colon. After that, print the compact representation of every visually appealing flag with stars, one per line.
Print the arrangements in increasing order of the number of stars in the first row. When two arrangements have the same first row, print the one with fewer stars in the second row first. The arrangement with a single row of stars and the arrangement with rows of one star are trivial, so do not print them.
Write each compact representation in the form "x,y", with exactly one comma between x and y and no other characters.