Perfect Pilgrimage
Time limit1sMemory limit1024 MB
Choose N lattice points forming a counterclockwise polygon with no crossing edges and at least K equal sides, or report that no such choice exists.
- Level
Hard8 of 10
- Topics
- Geometry, Math, Implementation
- Solved
- No attempts yet
Problem
A pilgrim keeps on a pilgrimage that seems like it will never end. The pilgrim moves from the holy site where they are to another holy site, and prays to God each time they arrive at a site.
At the center of the earth is the Great Holy Site, and holy sites are lined up at regular intervals around it. The position of a holy site is written as , which means the site is miles east of the Great Holy Site and miles north of it. If , the site is miles west. If , the site is miles south. Here, a mile is the distance God walks in a thousand steps.
For every integer pair with , a site exists at , so there are exactly holy sites on the earth.
The pilgrim chooses of these sites, visits them in order, and then returns to the first site chosen. The pilgrim wants the chosen sites to form a perfect regular -gon, the shape God likes most. A regular -gon has many properties. The following are representative:
- It is a convex polygon.
- All sides have equal length.
- All angles have equal size.
Since and are both integers, a perfect regular -gon may be impossible to build. So the pilgrim relaxes the conditions and selects sites that satisfy the following. For convenience, the -th site is treated as the same as the -th site.
- The -th, -th, and -th sites are located counterclockwise.
- Let be the Euclidean distance between the -th and -th sites. There must be at least integers with such that .
- For every integer with , the segment connecting the -th and -th sites and the segment connecting the -th and -th sites must not intersect.
Determine whether the pilgrim can choose sites satisfying these conditions. If so, find the positions of the sites and the order in which they must be chosen.
Input
The first line contains two positive integers and (, ), the number of sites to choose and the distance condition.
Output
On the first line, print YES if the pilgrim can choose sites satisfying the conditions, and NO otherwise.
If such sites exist, print more lines. The -th line contains two integers and , separated by a space, giving the position of the -th chosen site. Every printed position must be an existing site for the answer to be accepted.