308409: CF1514C. Product 1 Modulo N

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Product 1 Modulo N

题意翻译

#### 题目大意: 给定一个正整数 $n$ ,找到排列 $[1,2,...,n-1]$ 的最长子序列,使它满足它元素的乘积模 $n$ 意义下为 $1$ 。 注意:子序列的定义: $b$ 是 $a$ 的子序列当且仅当可以通过删去 $a$ 的若干个(可以是 $0$ 个) 元素得到 $b$ 。 #### 输入格式: 一行一个正整数 $n$ ($2 \le n \le 10^5$),意义如题所述。 #### 输出格式: 第一行一个正整数 $len$ ,表示最长子序列的长度。 第二行以升序输出子序列中的元素。 如果有多组数据,可以输出任意一个。

题目描述

Now you get Baby Ehab's first words: "Given an integer $ n $ , find the longest subsequence of $ [1,2, \ldots, n-1] $ whose product is $ 1 $ modulo $ n $ ." Please solve the problem. A sequence $ b $ is a subsequence of an array $ a $ if $ b $ can be obtained from $ a $ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $ 1 $ .

输入输出格式

输入格式


The only line contains the integer $ n $ ( $ 2 \le n \le 10^5 $ ).

输出格式


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.

输入输出样例

输入样例 #1

5

输出样例 #1

3
1 2 3

输入样例 #2

8

输出样例 #2

4
1 3 5 7

说明

In the first example, the product of the elements is $ 6 $ which is congruent to $ 1 $ modulo $ 5 $ . The only longer subsequence is $ [1,2,3,4] $ . Its product is $ 24 $ which is congruent to $ 4 $ modulo $ 5 $ . Hence, the answer is $ [1,2,3] $ .

Input

题意翻译

#### 题目大意: 给定一个正整数 $n$ ,找到排列 $[1,2,...,n-1]$ 的最长子序列,使它满足它元素的乘积模 $n$ 意义下为 $1$ 。 注意:子序列的定义: $b$ 是 $a$ 的子序列当且仅当可以通过删去 $a$ 的若干个(可以是 $0$ 个) 元素得到 $b$ 。 #### 输入格式: 一行一个正整数 $n$ ($2 \le n \le 10^5$),意义如题所述。 #### 输出格式: 第一行一个正整数 $len$ ,表示最长子序列的长度。 第二行以升序输出子序列中的元素。 如果有多组数据,可以输出任意一个。

加入题单

算法标签: