H 题意

n个数哈希,策略是直接模一个数。求最小的不冲突模数
范围0-50w

H 思路

冲突时当且仅当|ai-aj|%m=0
换句话说,m不能是任何一对aiaj的约数,数的范围不大,如果我们能知道所有|ai-aj|,那么我们枚举m,判断下他每一个倍数有没有出现过,就可以判断m是否可以做答案。这个复杂度是调和级数,nlogn级别的。
下面问题在于我们如何知道所有的ai-aj。这里需要一个前置知识。我们把ai看作多项式f1中x^ai
的系数,aj同样处理。那么所有ai+aj可以通过对两个多项式进行卷积得出。(显然,卷积后如果 x^k 的系数不为0,说明有两项相乘为k的情况,根据多项式的生成方式,也就是ai+aj=存在)。那么如果是ai-aj呢?不难发现可以把aj放在x^-aj的系数上。但fft不支持这种操作,那我们可以整体给他上一个偏移量d,似的所有d-aj>=0,我们卷积完之后次数全部减d就可以了。

H 代码

#include<cstdio>
#include<iostream>
#include<set>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<chrono>
#include<bitset>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
#define int long long
//#define double long double
using namespace std;typedef long long ll;const int maxn=2100505;const int inf=0x3f3f3f3f;const int mod=998244353;const int g=3;//原根int n,m,k;int a[maxn],b[maxn]; int rv[maxn];int len,cnt;int binpow(int a,int b=mod-2){a%=mod;int res = 1;while(b>0){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res%mod;}void change(){for(int i=0;i<len;i++)rv[i]=(rv[i>>1]>>1)|((i&1)<<(cnt-1));}void NTT(int *c,int type){for(int i=0;i<len;i++)if(i<rv[i]) swap(c[i],c[rv[i]]);for(int mid=1;mid<len;mid<<=1){int wn=binpow(g,(mod-1)/(mid*2));if(type==-1)  wn=binpow(wn);for(int R=mid<<1,j=0;j<len;j+=R){int w=1;for(int k=0;k<mid;k++,w=(w*wn)%mod){int x=c[j+k],y=w*c[j+mid+k]%mod;c[j+k]=(x+y)%mod;c[j+mid+k]=(x-y+mod)%mod;}}}if(type==-1){int re=binpow(len);for(int i=0;i<len;i++)c[i]=c[i]*re%mod;}}void solve(){cin>>n;while(n--){int t;cin>>t;a[t]++;b[500005-t]++;}len=1,cnt=0;while(len<=1000000)  len*=2,cnt++;change();NTT(a,1);NTT(b,1);for(int i=0;i<=len;i++){a[i]=1ll*a[i]*b[i]%mod;}NTT(a,-1);bool ok=1;for(int i=1;;i++){ok=1;for(int j=i;j<500005;j+=i){if(a[j+500005]){ok=0;break;}}if(ok){cout<<i<<endl;return ;}}}signed main(){IOS#ifndef ONLINE_JUDGEfreopen("IO\\in.txt","r",stdin);freopen("IO\\out.txt","w",stdout);#endifint tn=1;//cin>>tn;for(int __=1;__<=tn;__++){solve();}} 

2021牛客多校1 H hashfunction FTT/NTT,数论相关推荐

  1. 2021牛客多校9 - Cells(推公式+NTT)

    题目链接:点击查看 题目大意:初始时给出 nnn 个点,分别为 {(0,a0),(0,a1),⋯,(0,an)}\{(0,a_0),(0,a_1),\cdots,(0,a_n)\}{(0,a0​),( ...

  2. LCS(2021牛客多校4)

    LCS(2021牛客多校4) 题意: 让你构造三个字符串s1,s2,s3,长度均为n,要求LCS(s1,s2)=a,LCS(s2,s3)=b,LCS(s1,s3)=c 题解: 先考虑三个串互相LCS为 ...

  3. 【2021牛客多校2】F-Girlfriend 计算几何

    2021牛客多校2-F F-Girlfriend 题目大意 给出四个点 A , B , C , D A, B, C, D A,B,C,D 另有两点 P 1 , P 2 P_1, P_2 P1​,P2​ ...

  4. 2021牛客多校第八场补题 D-OR

    链接:https://ac.nowcoder.com/acm/contest/11259/D 来源:牛客网 题目描述 There are two sequences of length n−1n-1n ...

  5. 2021牛客多校第五场补题

    B-Boxes 链接:https://ac.nowcoder.com/acm/contest/11256/B 来源:牛客网 题目描述 There're nn_{}n​ boxes in front o ...

  6. K-Stack 2021牛客多校2

    链接:https://ac.nowcoder.com/acm/contest/11253/K 来源:牛客网 题目描述 ZYT had a magic permutation a1,a2,⋯ ,an a ...

  7. FFT ---- 2021牛客多校第一场 H Hash Function

    题目链接 题目大意: 解题思路: 首先我们知道任意两个数%seed\%seed%seed都不相同→\rightarrow→(aj−ai)%seed≠0(∀ai≤aj)(a_j-a_i)\%seed\n ...

  8. 【多校训练】2021牛客多校5

    [前言] 很久没有时间整理题解了,补题和打游戏的时间居多(doge) 这场其实主要F出题人数据有锅,花太多时间了(赛后重测是一血),然后后面G想歪了爆搜剪枝没过,I的回滚莫队队友前一天写了结果今天写不 ...

  9. 线段树 ---- 2021牛客多校第一场 J Journey among Railway Stations [线段树维护区间可行性判断]

    题目链接 题目大意: 一段路上有 NNN 个点,每个点有一个合法时间段[ui,vi][u_i,v_i][ui​,vi​],相邻两个点有一个长度wiw_iwi​.有qqq次询问,每次询问,在 [ui,v ...

最新文章

  1. hadoop 1.x升级至hadoop-2.2.0记录
  2. 首份《顶级数据团队建设全景报告》重磅发布: 逾半数据团队称人才储备不足
  3. 利用go语言创建web server的两种方式
  4. Gateway网关-过滤器链执行顺序
  5. Linux/Ubuntu: 命令行任务(To-Do List)管理 task - A command line todo manager
  6. 北京市通信管理局对3·15晚会曝光的北京企业作出行政处罚
  7. 利用DB Link搞定Oracle两个数据库间的表同步
  8. 普通软件项目开发过程规范(五)—— 总结
  9. Python读写Excel简单案例及调试说明文档
  10. 嵌入式开发技术汇总001+modbus RTU调试四件套 : modbus poll 7 ; modbus slave 6;modscan32;MThings 使用教程
  11. 个人计算机系统的不稳定原因,cpu使用率忽高忽低怎么办 电脑cpu使用率不稳定原因分析【详解】...
  12. 手写一个类似 element-ui 的可输入下拉选择
  13. EFR32BG22性能
  14. ios安装并信任证书
  15. pages改变文档背景和改变文字背景
  16. Git - SSL_ERROR_SYSCALL 问题解决
  17. 初学python的体会心得-python学习心得:如何入门
  18. php windows vld,PHP安装VLD查看opcode
  19. 低压抽屉柜常见故障处理方法_低压开关柜的常见故障及处理方法
  20. shader学习笔记(二)

热门文章

  1. 计算机是如何跑起来的百度云,《程序是怎样跑起来的》(下)
  2. 操作系统实验三:主存空间的分配与回收
  3. 方倍工作室微信相关代码下载方法
  4. 西安电子科技大学计算机类考研数据速览
  5. .net core 3.1 WebApi项目/Swagger支持二级目录
  6. scrapy 爬取链家二手房数据
  7. shell之正则表达式及grep命令
  8. C++笔记 文件处理笔记
  9. HashCat配GPU
  10. grep检索关键字的命令_文件中查找关键字“ ”命令 grep