Product of numbers P44833


Statement
 

pdf   zip

Given a set of nn natural numbers, choose any subset SS such that xS1(modn)\prod_{x \in S} \equiv 1 \pmod{n}.

Input

Input consists of several cases. Every case begins with nn, followed by nn different numbers, all between 1 and 10910^9. Assume 2n1052 \le n \le 10^5.

It is easy to see that no number xx where gcd(x,n)1\mbox{gcd}(x, n) \ne 1 could ever be part of any solution. Consequently, every given xx is such that gcd(x,n)=1\mbox{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 nn. 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”.

Public test cases
  • Input

    5  9 8 2 6 4
    5  9 8 2 6 4
    2  1 3
    4  10000003 10000007 10000011 10000015
    5  23 18 3 8 13
    

    Output

    8 2
    9 8 6 4 2
    3
    10000003 10000007
    23 18 3 8
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++