eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Poly-polygonal Numbers

Poly-polygonal Numbers

Полигональным называется число, которое может быть представлено расположением точек в виде правильного многоугольника. Некоторые примеры показаны на рисунке ниже.

prb6074

Первый рисунок показывает первые 4треугольных числа 1, 3, 6, 10. Следующие три рисунка показывают первые четыре квадратных, пятиугольных и шестиугольных чисел. В общем случае k- гональными являются числа, для которых точки образуют правильный k-угольник (треугольные числа являются 3-гональными, квадратные числа 4-гональными и так далее). Определим k как индекс полигонального числа. В этой задаче следует найти числа, являющиеся k-гональными для двух или более значений k. Такие числа назовем поли-гональными.

Входные данные

Consist of multiple problem instances. Each instance will consist of 3 lines. The first line will be a non-negative integer n50 indicating the number of types of polygonal numbers of interest in this problem. Note that this line may be longer than 80 characters. The next line will contain n integers indicating the indices of these polygonal numbers (all distinct and in increasing order). For example, if the first line contained the value 3, and the next line contained the values 3 6 10, then that problem instance would be interested in 3-gonal, 6-gonal and 10-gonal numbers. Each index k will lie in the range 3k1000. The last line of the problem instance will consist of a single positive integer s10000, which serves as a starting point for the search for poly-polygonal numbers. A value of n = 0 terminates the input.

Выходные данные

For each problem instance, you should output the next 5 poly-polygonal numbers which are greater than or equal to s. Each number should be on a single line and conform to the following format:

num:k[1] k[2] k[3] ...

where num is the poly-polygonal number, and k1, k2, k3 ... are the indices (in increasing order) of the poly-polygonal number equal to num. A single space should separate each index, and you should separate each problem instance with a single blank line. The judges input will be such that the maximum value for any poly-polygonal number will t in a long variable.

Лимит времени 1 секунда
Лимит использования памяти 128 MiB
Входные данные #1
10
6 7 8 9 10 11 12 13 14 15
1000
5
3 4 13 36 124
1
0
Выходные данные #1
1216:9 12
1540:6 10
1701:10 13
2300:11 14
3025:12 15

1:3 4 13 36 124
36:3 4 13 36
105:3 36
171:3 13
1225:3 4 124
Источник 2000 North America, East Central Regional Contest, Задача B