为什么我用快读只有20分,用cin却100?
查看原帖
为什么我用快读只有20分,用cin却100?
947041
wj2008楼主2024/7/16 09:18
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int s1,s2;
int read(){
	int s=0,h=1;
	char e=getchar();
	while(e<'0'||e>'9'){
		if(e=='-'){
			h*=-1;
		}
		e=getchar();
	}
	while(e>='0'&&e<='9'){
		s=(s<<3)+(s<<1)+e^48;
		e=getchar();
	}
	return s*h;
}
void exgcd(int a,int &x,int b,int &y){
	if(b==0){
		x=1,y=0;
		return;
	}
	exgcd(b,x,a%b,y);
	int t=x;
	x=y;
	y=t-(a/b)*y;
}
signed main(){
	int x,y,n,m,l;
	x=read(),y=read(),m=read(),n=read(),l=read();
    //cin>>x>>y>>m>>n>>l;
	int A=n-m,B=x-y;
	if(A<0){
		A=-A;
		B=-B;
	}
	int g=__gcd(A,l);
	exgcd(A,s1,l,s2);
	if(B%g!=0){
		cout<<"Impossible";
		return 0;
	}
	//cout<<s1<<" "<<s2<<" "<<g<<" "; 
	cout<<((s1*(B/g))%(l/g)+(l/g))%(l/g);
}
2024/7/16 09:18
加载中...