|
||||||||||
Draw Regular PolygonTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 394 Accepted Submission(s): 74 Problem Description A regular polygon is a polygon whose all angles are equal in measure and all sides have the same length. Great mathematician Carl Friedrich Gauss had drawn a regular heptadecagon with only ruler and compass when he was 19. But today, we will not draw regular polygons that way. You had a circle of unit radius and some rulers, each can only measure certain distance, which equals to 2 sin (k*PI/n) , where n and k are known for each ruler. Thus you can measure an arc of 2k*PI/n on that circle with a ruler of parameters n and k. Rulers can be used only to measure arcs on that circle, othe uses are forbidden. Each ruler can be used arbitrary many times. Now give you the parameters of r rulers, how many different regular polygons can you draw? Two regular polygons are said to be the same if they had the same number of sides, but may be differ in orientations. And a regular polygon should have at least 3 sides. Input Each test case begins with an integer r(1 <= r <=30) the number of rulers, on the first line. Then r lines followed, each line describes a ruler with two positive integers n(1 <= n <= 104) and k(1 <= k <= 104), indicate that ruler can measure a distance of 2 sin k*PI/n . Output Output two lines for each test case, the number of different regular polygons that can be drawn with the r rulers on the first line. Then output the possible numbers of sides of the polygons in ascending order on the second line, separate adjacent numbers by a single space. if the answer is greater than 16, only output the first 16 of them. If no polygons can be drawn, do not output the second line. Sample Input
Sample Output
Author Cauchy (Special thanks WJH) Source | ||||||||||
|