0%

Product 1 Modulo N

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 nn, find the longest subsequence of 1,2,,n11,2,…,n−1 whose product is 11 modulo nn.” Please solve the problem.

A sequence bb is a subsequence of an array aa if bb can be obtained from aa by deleting some (possibly all) elements. The product of an empty subsequence is equal to 11.

Input

The only line contains the integer nn (2n1052≤n≤10^5).

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
2
3
1 2 3

input

1
8

output

1
2
4
1 3 5 7

Note

In the first example, the product of the elements is 66 which is congruent to 11 modulo 55. The only longer subsequence is [1,2,3,4][1,2,3,4]. Its product is 2424 which is congruent to 44 modulo 55. Hence, the answer is [1,2,3][1,2,3].

Tutorial

gcd(x,n)1gcd(x, n) \neq 1,那么不存在一个数 yy 使得 xy1 (mod n)xy \equiv 1 \ (mod \ n) ,所以这 kk 个数中必不包括与 nn 不互质的数,而所有与 nn 互质的数的乘积 BB 满足 B1 (mod n)B \equiv 1 \ (mod \ n) 或者 B1 (mod n)B \equiv -1 \ (mod \ n)

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6+1;
int a[maxn], tot;

int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
long long ans = 1;
for(int i = 1; i < n; ++ i) {
if (__gcd(i, n) == 1) {
a[++tot] = i;
ans = ans * i % n;
}
}
if (ans != 1) tot --;
cout << tot << "\n";
for(int i = 1; i <= tot; ++ i) {
cout << a[i] << " \n"[i==tot];
}
return 0;
}
-------------本文结束感谢您的阅读-------------