Impressive Integers
Time limit1sMemory limit512 MB
Given n up to 1000, decide whether an equilateral triangle can be tiled by n equilateral triangles of only two side lengths, and print such a tiling if one exists.
- Level
Medium7 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Recently, Alice and her sister Clara learned about adorable numbers. A positive integer is called adorable if there exist integers , , and such that an equilateral triangle with side length can be tiled with smaller equilateral triangles, each having side length or . For instance, is adorable, as shown in Figure I.1a below.
They decided to see who could come up with more adorable numbers, but checking all numbers by hand is too cumbersome. Alice therefore asked you to check whether the numbers Clara listed are adorable. Because she wants to be sure that every number claimed to be adorable really is, she asked you to write a program that, given an integer , determines whether it is adorable. If it is, the program outputs a valid tiling as shown in Figure I.1a.
Input
The input consists of:
- A single positive integer ().
Output
If is adorable, output a valid tiling in the following format:
-
Three integers () such that an equilateral triangle with side length can be tiled with equilateral triangles with side lengths and .
-
lines, each describing one triangle and consisting of:
- one of
AandB, specifying whether the side length of the triangle is or ; - two integers , giving the leftmost corner of the triangle;
- one of
UandD, specifying whether the triangle points upward or downward.
- one of
These triangles must form a valid tiling of the equilateral triangle with corners at and , where all coordinates use the coordinate system in Figure I.1b.
If is not adorable, output impossible.
If your tiling consists of triangles that all have the same size, you may use either A or B exclusively for all triangles, or set and label each triangle with A or B arbitrarily.
It can be shown that a tiling following these rules exists for every adorable number in the input range. You may output any valid tiling.

