当前位置:网站首页>C. Product 1 Modulo N-Codeforces Round #716 (Div. 2)
C. Product 1 Modulo N-Codeforces Round #716 (Div. 2)
2022-06-23 16:58:00 【Qin Sanma】
C. Product 1 Modulo N
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Now you get Baby Ehab's first words: "Given an integer nn, find the longest subsequence of [1,2,…,n−1][1,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 (2≤n≤1052≤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
input
Copy
5
output
Copy
3 1 2 3
input
Copy
8
output
Copy
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].
=========================================================================
First pair 50 All numbers within dfs I found that the selected numbers are all coprime numbers , The only difference is , Some figures have been chosen n-1 Some have no choice , We can judge the product of all coprime numbers , If it is 1, Then output the answer directly , Otherwise, remove one n-1 Output the rest .
# include<iostream>
# include<algorithm>
# include<math.h>
# include<queue>
using namespace std;
typedef long long int ll;
int ans[1000000+10];
int main()
{
int n;
cin>>n;
int len=1;
ll sum=1;
for(int i=1;i<n;i++)
{
if(__gcd(i,n)==1)
{
ans[len]=i;
sum*=i;
sum%=n;
len++;
}
}
if(sum==1)
{
cout<<len-1<<endl;
for(int i=1;i<=len-1;i++)
{
cout<<ans[i]<<" ";
}
}
else
{
cout<<len-2<<endl;
ll temp=1;
for(int i=1;i<=len-2;i++)
{
cout<<ans[i]<<" ";
temp*=ans[i];
}
}
return 0;
}边栏推荐
- Robot Orientation and some misunderstandings in major selection in college entrance examination
- Leetcode: interview question 08.13 Stacking bin [top-down DFS + memory or bottom-up sorting + DP]
- Comparison of asemi Schottky diode and ultrafast recovery diode in switching power supply
- 谈谈redis缓存击穿透和缓存击穿的区别,以及它们所引起的雪崩效应
- Asemi ultrafast recovery diode es1j parameters, es1j package, es1j specification
- 图扑数字孪生 3D 风电场,智慧风电之海上风电
- Stick to five things to get you out of your confusion
- 查数据库中每张表的大小
- R语言使用yardstick包的rmse函数评估回归模型的性能、评估回归模型在每个交叉验证(或者重采样)的每一折fold上的RMSE、以及整体的均值RMSE(其他指标mae、mape等计算方式类似)
- ABP framework - data access infrastructure (Part 2)
猜你喜欢

ASEMI肖特基二极管和超快恢复二极管在开关电源中的对比

leetcode:面试题 08.13. 堆箱子【自顶而下的dfs + memory or 自底而上的排序 + dp】

Apache基金会正式宣布Apache InLong成为顶级项目

The summary of high concurrency experience under the billion level traffic for many years is written in this book without reservation

测试的重要性及目的

Safe and comfortable, a new generation of Qijun carefully interprets the love of the old father

以 27K 成功入职字节跳动,这份《 软件测试面试笔记》让我受益终身

Why do we say that the data service API is the standard configuration of the data midrange?

Jetpack compose and material you FAQs

leetcode:面試題 08.13. 堆箱子【自頂而下的dfs + memory or 自底而上的排序 + dp】
随机推荐
ASEMI肖特基二极管和超快恢复二极管在开关电源中的对比
Talk about the difference between redis cache penetration and cache breakdown, and the avalanche effect caused by them
The Google play academy team PK competition is in full swing!
Opengauss database source code analysis series articles -- detailed explanation of dense equivalent query technology (Part 2)
What can the accelerated implementation of digital economy bring to SMEs?
炒股买股票需要怎么选择呢?安全性不错的?
Intel arc A380 graphics card message summary: the entry-level price products of running point and bright driving need to be optimized
使用Jmeter进行性能测试及性能监控平台搭建
R language uses colorblinr package to simulate color blind vision, and uses edit to visualize the image of ggplot2_ The colors function is used to edit and convert color blindness into visual results
Golang writes to JSON files
Amadis publishes Ola payment processing standards
官方零基础入门 Jetpack Compose 的中文课程来啦
供求两端的对接将不再是依靠互联网时代的平台和中心来实现的
Apache基金会正式宣布Apache InLong成为顶级项目
混沌工程在云原生中间件稳定性治理中的实践分享
图扑软件以轻量化建模构建智慧城市
Leetcode 450. Delete node in binary search tree
golang goroutine、channel、time代码示例
亚朵更新招股书:继续推进纳斯达克上市,已提前“套现”2060万元
Is your PCB ground wire right? Why should we have a master land?