C. Product 1 Modulo N(数论+打表)

68 篇文章 1 订阅

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;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值