传送门
大意:
给你一个数n,让你从1至n-1中选择最多的数相乘,使乘积模n为1.
不能选与n不互质的数
因为 gcd(乘积,n)!=1, 那么乘积%n一定不为1
易证:m个与n互质的数的乘积也必然与n互质
所以,s=cj%n, s一定在前面取的中,
若s!=1, 从前面所取的数中去掉s即可
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int gcd(int a,int b)
{
if(a%b==0) return b;
return gcd(b,a%b);
}
int ans[N];
signed main()
{
int n;
cin>>n;
int tot=0, s=1;
for(int i=2;i<=n-1;i++)
{
if(gcd(i,n)==1)
{
ans[++tot]=i;
s=s*i%n;
}
}
if(s!=1) cout<<tot<<endl;
else cout<<tot+1<<endl;
cout<<1<<' ';
for(int i=1;i<=tot;i++)
{
if(ans[i]!=s) cout<<ans[i]<<' ';
}
return 0;
}