摘要:#include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i,a,n) for (int i=a;i=a;i--) #define pb push_back #define mp make_p...
阅读全文
摘要:int fac[]={1,1,2,6,24,120,720,5040,40320,362880}; int Cantor(int *s,int n)//从1开始编号 { int ans=0; for(int i=0;i<n;i++){ int tmp=0; for(int j=i+1;j<n;j++) if(s[j]<s[i...
阅读全文
摘要:#include #include using namespace std; long long Gcd(long long a,long long b){ return b==0?a:Gcd(b,a%b); } long long cal(long long n,int *p,int cnt){ long long res=0; for(int i=1;i>=1; ...
阅读全文
摘要:#include using namespace std; #define ll long long ll Left[10+5],M[10+5]; ll exgcd(ll a,ll b,ll &x,ll &y){ if(!b){x=1,y=0;return a;} ll re=exgcd(b,a%b,x,y),tmp=x; x=y,y=tmp-(a/b)*y; r...
阅读全文
摘要:#define ll long long ll Exgcd(ll a,ll b,ll& x,ll& y){ if(a%b==0){ x=0,y=1; return b; } ll r,tx,ty; r=Exgcd(b,a%b,tx,ty); x=ty; y=tx-a/b*ty; } ll Comp(ll a,ll...
阅读全文
摘要:const int maxn=1000000+5; bool check[maxn]; int prime[maxn],mu[maxn]; void Moblus(int n){ memset(check,0,sizeof(check)); mu[1]=1; int tot=0; for(int i=2;in) break; check[i...
阅读全文
摘要:const int maxn=30000+5; int prime[maxn]; void marktable(int n){ memset(prime,0,sizeof(prime)); for(int i=2;i T fast_mod(T a,T b,T1 Mod){ a%=mod; if(b==0) return 1; T ans=1,base=a...
阅读全文
摘要:1 O(n*logn) 同时生成素数表 2 O(n)同时生成素数表 3 只生成素数筛
阅读全文
摘要:const int maxn=3000000; ll inv[maxn+5]; void marktable_inv(int p){ inv[0]=inv[1]=1; for(int i=2;i<maxn;i++) inv[i]=(p-p/i)*inv[p%i]%p; }
阅读全文
摘要:扩展BSGS用于求解axΞb mod(n) 同余方程中gcd(a,n)≠1的情况 基本思路,将原方程转化为a与n互质的情况后再套用普通的BSGS求解即可 const int maxint=((1<<30)-1)*2+1; struct Hashmap{ static const int Ha=999
阅读全文
摘要:离散对数问题是求解axΞb mod(n) 同余方程 以下模板使用于gcd(a,n)=1的情况
阅读全文
摘要:template T fast_mod(T a,T b,T Mod){ if(b==0) return 1; T ans=1,base=a; while(b!=0){ if(b&1)ans=(ans*base)%Mod; base=(base*base)%Mod; b>>=1; } return ans; }...
阅读全文
摘要:定义: 设m>1,gcd(a,m)=1,使得成立的最小正整数d为a对模m的阶,记为δm(a) 如果δm(a)=φ(m),则称a是模m的原根 定理:设m>1,gcd(a,m)=1,那么正整数x是同于方程的一个根当且仅当δm(a) | x 定理:由欧拉定理得 gcd(a,n)=1 定理:模m有原根的充要
阅读全文
摘要:template void exgcd(T a,T b,T &d,T &x,T &y){ if(!b) {d=a;x=1;y=0;} else {exgcd(b,a%b,d,y,x);y-=x*(a/b);} } //求解a*x=b mod n //如果有解那么解的个数有d=gcd(a,n)个 vector line_mod_equation(long long a,long l...
阅读全文
摘要://矩阵类,支持矩阵的加减乘和幂运算 //------------------------------------------------------------------------------------ const int MAXN = 105; const int MAXM = 105; struct Martix { int n, m; ...
阅读全文