注:均为开\(long\ long\)且未取模
#include<cstdio>
#include<algorithm>
#include<ctype.h>
#include<vector>
#include<queue>
#include<cstring>
#define lowbit(x) (x&-x)
#define ll long long
#define ld double
#include<map>
#include<stdlib.h>
#include<ctime>
#define mod 19260817
using namespace std;
int mg(int a,int b,int c)
{
int ans=1;
while(b)
{
if(b&1) ans=(ans*a)%c;
b>>=1;
a=a*a%c;
}
return ans;
}
int exgcd(int a,int b,int &x1,int &y1)
{
if(!b)
{
x1=1,y1=0;
return a;
}
int x2,y2;
int d=exgcd(b,a%b,x2,y2);
x1=y2,y1=x2-(a/b)*y2;
return d;
}
int crt(int a[],int m[],int n)
{
int M=1,ans=0;
for(int i=1;i<=n;i++) M*=m[i];
for(int i=1;i<=n;i++)
{
int ni,tmp;int mi=M/m[i];
exgcd(mi,m[i],ni,tmp);
if(!ni) ni=M;
ans=(ans+M*ni*a[i])%M;
}
return ans<0?ans+M:ans;
}
int excrt(int a[],int m[],int n)
{
int M=m[1],t,ni,tmp,d,ans=a[1];
for(int i=2;i<=n;i++)
{
d=exgcd(M,m[i],ni,tmp);
if((a[i]-ans)%d) return -1;
t=m[i]/d,ni*=(a[i]-ans)/d,ni=(ni%t+t)%t;
ans+=M*ni,M=M/d*m[i],ans%=M;
}
return ans<0?ans+M:ans;
}
int main(){}
原文地址:https://www.cnblogs.com/KatouKatou/p/9818355.html
时间: 2024-10-21 18:35:34