Product 1 Modulo N
time limit per test: 1 second
memory limit per test: 256 megabytes
Articles
Now you get Baby Ehab’s first words: “Given an integer , find the longest subsequence of whose product is modulo .” Please solve the problem.
A sequence is a subsequence of an array if can be obtained from by deleting some (possibly all) elements. The product of an empty subsequence is equal to .
Input
The only line contains the integer ().
Output
The first line should contain a single integer, the length of the longest subsequence.
The second line should contain the elements of the subsequence, in increasing order.
If there are multiple solutions, you can print any.
Examples
input
1 | 5 |
output
1 | 3 |
input
1 | 8 |
output
1 | 4 |
Note
In the first example, the product of the elements is which is congruent to modulo . The only longer subsequence is . Its product is which is congruent to modulo . Hence, the answer is .
Tutorial
若 ,那么不存在一个数 使得 ,所以这 个数中必不包括与 不互质的数,而所有与 互质的数的乘积 满足 或者 。
Code
1 |
|