Product of numbers

Given a set of n natural numbers, choose any subset S such that
∏_(x ∈ S) ≡ 1 (mod  n).

Input

Input consists of several cases. Every case begins with n, followed by n
different numbers, all between 1 and 10⁹. Assume 2 ≤ n ≤ 10⁵.

It is easy to see that no number x where gcd(x, n) ≠ 1 could ever be
part of any solution. Consequently, every given x is such that
gcd(x, n) = 1.

Output

Print one line for every case, with a non-empty subset of the given
numbers such that the product of its elements is congruent with 1 modulo
n. Each number can be used at most once. Print the numbers in any order,
and separated by one space. If there are several solutions, print any of
them. If there is no solution, print “Maths are difficult”.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T11:15:56.363Z

© Jutge.org, 2006–2026.
https://jutge.org
