problem

C. Product 1 Modulo N
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Now you get Baby Ehab’s first words: “Given an integer n, find the longest subsequence of [1,2,…,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.

Input
The only line contains the integer n (2≤n≤105).

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
inputCopy
5
outputCopy
3
1 2 3
inputCopy
8
outputCopy
4
1 3 5 7
Note
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].

C.产品1模数N
每次测试的时限1秒
每个测试的内存限制256 MB
输入标准输入
输出标准输出
现在,您得到Baby Ehab的第一句话:“给定整数n,找到乘积为1模n的最长[1,2,…,n-1]子序列。”请解决问题。

如果可以通过删除某些(可能是全部)元素从a获得b,则序列b是数组a的子序列。空子序列的乘积等于1。

输入
仅一行包含整数n(2≤n≤105)。

输出
第一行应包含一个整数,即最长子序列的长度。

第二行应按升序包含子序列的元素。

如果有多种解决方案,则可以打印任何解决方案。

例子
inputCopy
5
outputCopy
3
1 2 3
inputCopy
8
outputCopy
4
1 3 5 7
笔记
在第一个示例中,元素的乘积是6,等于1模5。唯一长的子序列是[1,2,3,4]。它的乘积是24,等于4模5。因此,答案是[1,2,3]。

solution

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;
int gcd(int a, int b){return !b?a:gcd(b,a%b);
}
int main(){ios::sync_with_stdio(false);int n;  cin>>n;vector<int>vc;LL ans=1;for(int i = 1; i <= n-1; i++){if(gcd(i,n)==1){vc.push_back(i);ans *= i;ans %= n;}}while(vc.size()>1 && ans%n!=1){ans /= vc.back();vc.pop_back();}cout<<vc.size()<<"\n";for(int i = 0; i < vc.size(); i++)cout<<vc[i]<<" ";return 0;
}

Codeforces Round #716 (Div. 2) C. Product 1 Modulo N相关推荐

  1. Codeforces Round #716 (Div. 2)

    Codeforces Round #716 (Div. 2) CodeForces 1514 题号 题目 知识点 难度 A Perfectly Imperfect Array B AND 0, Sum ...

  2. Codeforces Round #716 (Div. 2) D. Cut and Stick 主席树 + 思维

    传送门 文章目录 题意: 思路: 题意: 给你个长为nnn的数组aaa,定义好的区间为这个区间中每个数出现的次数≤⌈n2⌉\le \left \lceil \frac{n}{2} \right \rc ...

  3. Codeforces Round #716 (Div. 2) D(随机算法)

    Codeforces Round #716 (Div. 2) D 题意:区间查询,问区间最少能分成几部分使得最多的数不超过总数的一半 向上取整. 思路:找到区间的总数s,如果不超过一半的话就是一部分. ...

  4. Codeforces Round #716 (Div. 2) (位运算AND)

    B. AND 0, Sum Big time limit per test2 seconds memory limit per test256 megabytes inputstandard inpu ...

  5. Codeforces Round #716 Div.2 部分题解

    这场难度比之前几场友好了许多. A. Perfectly Imperfect Array 题意: 给出一个数组aaa,判断其是否存在一个子序列bbb使得bbb中的元素乘积不是平方数.若是,输出YES, ...

  6. Codeforces Round #716 (Div. 2)ABCDE题解

    目录 A.Perfectly Imperfect Array B.AND 0, Sum Big C.Product 1 Modulo N D.Cut and Stick 莫队 随机化算法(官方 线段树 ...

  7. Codeforces Round #566 (Div. 2)-E. Product Oriented Recurrence

    地址:https://codeforces.com/contest/1182/problem/E 思路:矩阵快速幂 fn=c^(2n−6)⋅f(n−1)⋅f(n−2)⋅f(n−3)=c^sc * f1 ...

  8. 主席树 | 莫队 ---- Codeforces Round #716 (Div. 2) D. Cut and Stick [主席树or莫队优化] 区间众数问题(静态)

    题目链接 题目大意: 就是给你nnn个数,和q次询问,每次询问给你一个区间[l,r][l,r][l,r],问你把区间里面的数分配成最少多少块,使得块内出现最多次数的数不超过区间长度的一半(除不尽向上取 ...

  9. D. Cut and Stick(Codeforces Round #716 (Div. 2))

    D. Cut and Stick 给定一个长度为nnn的数组,里面元素为a1,a2,a3,-,an−1,an,(1≤ai≤n)a_1, a_2, a_3, \dots, a_{n- 1}, a_n, ...

最新文章

  1. 最新android webview,Android 关于WebView全方面的使用(项目应用篇)
  2. .NET Core SignalR Redis底板详解(一)
  3. 怎么样用System.out.println在控制台打印出颜色
  4. 有关javabean的说法不正确的是_关于 JavaBean, 下列叙述中不正确的是 ( ) 。_学小易找答案...
  5. linux路由器实际配置案例
  6. Vue源码分析 - observer.js
  7. 百度Hi Csrf蠕虫攻击
  8. bzoj1036 [ZJOI2008]树的统计Count
  9. win10误删的注册表能还原吗_win10电脑注册表修改后如何恢复
  10. 迅雷手机版苹果版_迅雷IOS版恢复下载,又能用苹果手机下载电影愉快追剧了
  11. ARCGIS小工具(插件)免费版_自取_GIS插件_工具_其他
  12. 方格取数问题(网络流24题之一)
  13. 此生不戒多巴胺-冲刺集合
  14. 嵌入式学习中较好的练手项目和课题整理(附代码资料、学习视频和嵌入式学习规划)
  15. 【网单服务端】卡丁车深海之城单机游戏服务端+使用说明
  16. 求一个整数的各个位数
  17. 苹果7服务器是什么系统版本,最新系统 iOS14.7 Beta1 版本推出!
  18. 采访座谈快速出稿利器——讯飞智能录音笔SR502
  19. FFmpeg循环推流
  20. SQL查询语句-练习01+答案(含截图)

热门文章

  1. 【常识】—— 生物学
  2. 各种图示的介绍及绘制(boxplot、stem)
  3. Python 波浪线与补码
  4. Web 服务器错误代码
  5. 图论(一)—— 基本概念
  6. MathType 的使用
  7. hitool备份3798固件方法_创维E900s海思3798芯片当贝桌面不拆机通刷固件及刷机教程201910版...
  8. 条件编译宏定义_C语言学习- 预处理指令2 - 条件编译
  9. python基础教程第三版电子版-《python基础教程第三版》PDF高清完整版-免费下载...
  10. python中文叫什么-python中文叫什么