https://codeforces.com/contest/1514/problem/C
思路:证明日后补。
打表:
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+10;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
bool vis[maxn];
LL ans[maxn],tot=0;
void dfs(LL goal,LL mul,LL len,LL last){
if(mul%goal==0) return;
if(mul%goal==1){
if(len>tot){
tot=0;
for(LL i=1;i<goal;i++){
if(vis[i]){
ans[++tot]=i;
}
}
}
}
for(LL i=1;i<goal;i++){
if(!vis[i]&&i>last){///剪后能跑到20
vis[i]=true;
dfs(goal,mul*i,len+1,i);///别写成++len了...调了半个多小时
vis[i]=false;
}
}
}
int main(void){
cin.tie(0);std::ios::sync_with_stdio(false);
freopen("data.out","w",stdout);
LL limit=20;
for(LL num=2;num<=limit;num++){
tot=0;
dfs(num,1,0,0);
cout<<"num="<<num<<"答案序列为:";
cout<<tot<<"\n";
for(LL i=1;i<=tot;i++){
cout<<ans[i]<<" ";
}
cout<<"\n";
}
return 0;
}
num=2答案序列为:1
1
num=3答案序列为:1
1
num=4答案序列为:1
1
num=5答案序列为:3
1 2 3
num=6答案序列为:1
1
num=7答案序列为:5
1 2 3 4 5
num=8答案序列为:4
1 3 5 7
num=9答案序列为:5
1 2 4 5 7
num=10答案序列为:3
1 3 7
num=11答案序列为:9
1 2 3 4 5 6 7 8 9
num=12答案序列为:4
1 5 7 11
num=13答案序列为:11
1 2 3 4 5 6 7 8 9 10 11
num=14答案序列为:5
1 3 5 9 11
num=15答案序列为:8
1 2 4 7 8 11 13 14
num=16答案序列为:8
1 3 5 7 9 11 13 15
num=17答案序列为:15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
num=18答案序列为:5
1 5 7 11 13
num=19答案序列为:17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
num=20答案序列为:8
1 3 7 9 11 13 17 19
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],tot=0;
int main(void){
cin.tie(0);std::ios::sync_with_stdio(false);
LL n;cin>>n;
LL mod=n;
for(LL i=1;i<=n;i++){
if(__gcd(i,n)==1){
a[++tot]=i;
}
}
LL sum=1;
for(LL i=1;i<=tot;i++){
sum=(sum%mod*a[i]%mod)%mod;
}
if(sum!=1) tot--;
cout<<tot<<"\n";
for(LL i=1;i<=tot;i++){
cout<<a[i]<<" ";
}cout<<"\n";
return 0;
}