跳到正文

个人记录

MIKE28 罪证

kaikai_qwq约 15 分钟
原文

这是 2026年7月10日 存档的第 2 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

收录
2026年7月10日
更新
2026年8月15日
篇幅
约 15 分钟

版本

  1. v4当前
  2. v3
  3. v2
  4. v1

(以下 MIKE28 代码均来自 vjudge)

MIKE28 代码

C++
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll P=19940417,inv2=9970209,inv6=3323403;

ll m,n,l,r,ans,tmp1,tmp2,tmp3,a,b,c;

ll sum1(ll x){
    return x*(x+1)%P*inv2%P;
}

ll sum2(ll x){
    return x*(x+1)%P*(2*x+1)%P*inv6%P;
}

int main(){
    cin>>n>>m;
    if(n>m)
        swap(n,m);
    l=1,tmp1=n*n%P;
    while(l<=n)
        r=n/(n/l),tmp1=(tmp1-(sum1(r)-sum1(l-1)+P)%P*(n/l)%P+P)%P,l=r+1;
    l=1,tmp2=m*m%P;
    while(l<=m)
        r=m/(m/l),tmp2=(tmp2-(sum1(r)-sum1(l-1)+P)%P*(m/l)%P+P)%P,l=r+1;
    l=1,tmp3=0;
    while(l<=n)
        r=min(n/(n/l),m/(m/l)),a=(r-l+1)*n%P*m%P,b=(sum1(r)-sum1(l-1)+P)%P*((n/l)*m%P+(m/l)*n%P)%P,c=(sum2(r)-sum2(l-1)+P)%P*(n/l)%P*(m/l)%P,tmp3=(tmp3+a-b+c+P)%P,l=r+1;
    cout<<(tmp1*tmp2%P-tmp3+P)%P;
} 

受害题解 https://www.luogu.com.cn/article/iv19ilja

MIKE28 P2480 代码

C++
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int mod=999911658;

ll n,G,farc[50010],a[5],b[5]={0,2,3,4679,35617},val;

ll quickpow(ll a,ll b,ll p){
	ll res=1;
	while(b){
		if(b&1)
			res*=a,res%=p;
		a*=a,a%=p,b>>=1;
	}
	return res;
}

void init(ll p){
	farc[0]=1;
	for(ll i=1;i<=p;i++)
		farc[i]=farc[i-1]*i%p;
}

ll C(ll n,ll m,ll p){
	if(n<m)
		return 0;
	return farc[n]*quickpow(farc[m],p-2,p)%p*quickpow(farc[n-m],p-2,p)%p;
}

ll Lucas(ll n,ll m,ll p){
	if(n<m)
		return 0;
	if(!n)
		return 1;
	return Lucas(n/p,m/p,p)*C(n%p,m%p,p)%p;
}

void CRT(){
	for(ll i=1;i<=4;i++)
		val=(val+a[i]*(mod/b[i])%mod*quickpow(mod/b[i],b[i]-2,b[i]))%mod;
}

int main(){
	cin>>n>>G;
	if(G%(mod+1)==0){
		cout<<0;
		return 0;
	}
	for(ll k=1;k<=4;k++){
		init(b[k]);
		for(ll i=1;i*i<=n;i++)
			if(n%i==0){
				a[k]=(a[k]+Lucas(n,i,b[k]))%b[k];
				if(i*i!=n)
					a[k]=(a[k]+Lucas(n,n/i,b[k]))%b[k];
			}
	}
	CRT(),cout<<quickpow(G,val,mod+1);
}

受害题解 https://www.luogu.com.cn/article/1oe432az

MIKE28 P3807 代码

C++
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int n,m,p,tc,a[100006],b[100006];
ll fac[200006],g[200006],ans;
stack<int>s;

ll quickpow(ll x,ll y){
	ll ans=1;
	while(y){
		if(y&1)
			ans=(1ll*ans*x)%p;
		y>>=1;x=(x*x*1ll)%p;
	}
	return ans;
}

void pre(){
	a[0]=b[0]=0;
	while(n)
		s.push(n%p),n/=p;
	while(!s.empty())
		a[++a[0]]=s.top(),s.pop();
	int tmp=0;
	while(m)
		tmp++,s.push(m%p),m/=p;
	while(b[0]+tmp<a[0])
		b[++b[0]]=0;
	while(!s.empty())
		b[++b[0]]=s.top(),s.pop();
	fac[0]=1;
	for(int i=1;i<p;i++)
		fac[i]=(fac[i-1]*i)%p;
	g[p-1]=quickpow(fac[p-1],p-2);
	for(int i=p-2;i;i--)
		g[i]=(g[i+1]*(i+1))%p;
}

int main(){
	cin>>tc;
	while(tc--){
		cin>>n>>m>>p,n+=m,m=n-m,pre(),ans=1;
		for(int i=1;i<=a[0];i++){
			if(!b[i])
				continue;
			if(a[i]<b[i]){
				ans=0;
				break;
			}
			if(a[i]==b[i])
				continue;
			ans=(ans*fac[a[i]])%p,ans=(ans*g[b[i]])%p,ans=(ans*g[a[i]-b[i]])%p;
		}
		cout<<ans<<endl;
	}
	return 0;
}

受害题解 https://www.luogu.com.cn/article/8cd6dcyj

MIKE28 P4139 代码

C++
#include<bits/stdc++.h>

using namespace std;

const int MAXP=1e7;

int T,p,phi[MAXP+10];

void InitPhi() {
    phi[1]=1; 
    for(int i=2;i<=MAXP;i++)
        if(!phi[i])
            for(int j=i;j<=MAXP;j+=i){
                if(!phi[j])
                    phi[j]=j; 
                phi[j]=phi[j]/i*(i-1);
            }
}

inline int fastmul(int a,int x,int mod){
    int ret=0;
    while(x){
        if(x&1)
            ret=((ret%mod)+(a%mod))%mod;
        x>>=1,a=((a%mod)+(a%mod))%mod;
    }
    return ret;
}

inline int fastpow(int a,int x,int mod){
    int ret=1;
    while(x){
        if(x&1)
            ret=fastmul(ret,a,mod)%mod;
        x>>=1,a=fastmul(a,a,mod)%mod;
    }
    return ret;
}

int solve(int mod){
    if(mod==1)
        return 0;
    return fastpow(2,solve(phi[mod])+phi[mod],mod);
}

int main(){
    InitPhi();
    scanf("%d",&T);
    while(T--)
        scanf("%d",&p),printf("%d\n",solve(p));
}

受害题解 https://www.luogu.com.cn/article/9bd1bppw

MIKE28 P1173 代码

C++
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0},N=100001;

struct node{
	int x,y;
	node(){}
	node(int x,int y):x(x),y(y){}
};
queue<node>Q,q;
int tc,x[N],y[N],G[N*24],to[N*192],nxt[N*192],sz,cnt,p[N*24],dfsc,n,m,c,tmpx[N*24],tmpy[N*24],ctmp,t,tt,tx,ty;
bool ok,OK[N*24],cut[N*24];

struct Hash{
	int h[1000117],vx[N*25],vy[N*25],p[N*25],nxt[N*25],sz;
	void clear(){
		memset(h,0,sizeof(h)),sz=0;
	}
	void ins(int x,int y,int id){
		int pos=((ll)(x-1)*n+y-1)%1000117;
		vx[++sz]=x,vy[sz]=y,p[sz]=id,nxt[sz]=h[pos],h[pos]=sz;
	}
	int ask(int x,int y){
		for(int k=h[((ll)(x-1)*n+y-1)%1000117];k;k=nxt[k])
			if(vx[k]==x&&vy[k]==y)
				return p[k];
		return 0;
	}
}h,col,tem;

void add(int u,int v){
	to[++sz]=v,nxt[sz]=G[u],G[u]=sz,to[++sz]=u,nxt[sz]=G[v],G[v]=sz;
}

bool check(){
	int tx,ty;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(!h.ask(i,j)){
				for(int k=0;k<4;++k)
					if((tx=i+dx[k])&&tx<=n&&(ty=j+dy[k])&&ty<=m&&!h.ask(tx,ty))
						return 1;
				return 0;
			}
}

void bfs(int sx,int sy,int cl){
	int u,v,tx,ty;
	q.push(node(sx,sy)),col.ins(sx,sy,cl);
	while(!q.empty()){
		u=q.front().x,v=q.front().y,q.pop();
		for(int i=0;i<4;++i)
			if((tx=u+dx[i])&&tx<=n&&(ty=v+dy[i])&&ty<=m&&h.ask(tx,ty)>0&&!col.ask(tx,ty))
				col.ins(tx,ty,cl),q.push(node(tx,ty));
	}
}

bool bfs2(int sx,int sy){
	int u,v,t;
	q.push(node(sx,sy)),tem.ins(sx,sy,-1);
	while(!q.empty()){
		u=q.front().x;v=q.front().y;q.pop();
		for(int x=max(1,u-1);x<=n&&x<=u+1;++x)
			for(int y=max(1,v-1);y<=m&&y<=v+1;++y)if((t=h.ask(x,y))&&!tem.ask(x,y))
				if(t==-1)
					tem.ins(x,y,-1),q.push(node(x,y));
				else
					tmpx[++ctmp]=x,tmpy[ctmp]=y;
	}
	if(ctmp==-1)
		return 1;
	for(int i=1,t=col.ask(tmpx[0],tmpy[0]);i<=ctmp;++i)
		if(col.ask(tmpx[i],tmpy[i])!=t)
			return 0;
	return 1;
}

bool ncon(){
	int u,v,ccl=0;
	col.clear();
	while(!Q.empty()){
		u=Q.front().x,v=Q.front().y,Q.pop();
		if(col.ask(u,v))
			continue;
		bfs(u,v,++ccl);
	}
	tem.clear();
	for(int i=0;i<c;++i)
		if(!tem.ask(x[i],y[i])){
			ctmp=-1;
			if(!bfs2(x[i],y[i]))
				return 1;
		}
	return 0;
}

int dfs(int u,int fa){
	int v,lowu=p[u]=++dfsc,lowv,chd=0;
	for(int i=G[u];i;i=nxt[i])
		if((v=to[i])!=fa)
			if(!p[v]){
				++chd;
				if((lowv=dfs(v,u))>=p[u])
					cut[u]=1;
				if(lowv<lowu)
					lowu=lowv;
			}else
				if(p[v]<lowu)
					lowu=p[v];
	if(!fa&&chd==1)
		cut[u]=0;
	return lowu;
}

int main(){
	cin>>tc;
	while(tc--){
		cin>>n>>m>>c,h.clear();
		for(int i=0;i<c;++i)
			cin>>x[i]>>y[i],h.ins(x[i],y[i],-1);
		if((ll)n*m-c<2ll){
			puts("-1");
			continue;
		}
		if((ll)n*m-c==2ll){
			puts(check()?"-1":"0");
			continue;
		}
		memset(G,0,sizeof(G)),ok=sz=cnt=dfsc=0,memset(p,0,sizeof(p)),memset(cut,0,sizeof(cut)),memset(OK,0,sizeof(OK));
		for(int i=0;i<c;++i)
			for(int j=max(1,x[i]-2);j<=x[i]+2&&j<=n;++j)
				for(int k=max(1,y[i]-2);k<=y[i]+2&&k<=m;++k)
					if(!(t=h.ask(j,k))){
						h.ins(j,k,++cnt),Q.push(node(j,k)),OK[cnt]=max(abs(j-x[i]),abs(k-y[i]))<=1;
						for(int l=0;l<4;++l)
							if((tx=j+dx[l])&&tx<=n&&(ty=k+dy[l])&&ty<=m&&(tt=h.ask(tx,ty))>0)
								add(cnt,tt);
					}else
						if(t>0&&max(abs(j-x[i]),abs(k-y[i]))<=1)
							OK[t]=1;
		if(ncon()){
			puts("0");
			continue;
		}
		if(n==1||m==1){
			puts("1");
			continue;
		}
		for(int i=1;i<=cnt;++i){
			if(!p[i])
				dfs(i,0);
			if(OK[i]&&cut[i]){
				puts("1"),ok=1;
                break;
			}
		}
		if(!ok)
			puts("2");
	}
}

受害题解 https://www.luogu.com.cn/article/pqud2ca2

并且你可以发现前面几个代码中的快速幂变量名基本不一样,但是这种简单的板子每次写基本不会有差别,