求助(玄关)
查看原帖
求助(玄关)
692026
flyO楼主2025/7/28 09:39
#include<bits/stdc++.h>
using namespace std;
long long T,a,b,c,d,k,t,x,y,minx,miny,maxx,maxy,p1,p2;
void exGCD(long long a,long long b){
	if(b==0){
		x=1,y=0;
		return;
	}
	exGCD(b,a%b);
	long long t=x;
	x=y;
	y=t-a/b*y;
}
long long gcd(long long a,long long b){
	if(b==0) return a;
	return gcd(b,a%b);
}
int main(){
	cin>>T;
	while(T--){
		cin>>a>>b>>c;
		d=gcd(a,b);
		if(c%d){
			cout<<"-1\n";
			continue;
		}
		k=c/d;
		exGCD(a,b);
		x*=k,y*=k,p1=b/d,p2=a/d;
		t=-x/p1;
		if(x+t*p1<=0) ++t;
		minx=x+t*p1;
		maxy=y-t*p2;
		t=y/p2;
		if(y-t*p2<=0) --t;
		miny=y-t*p2;
		maxx=x+t*p1;
		if(maxy<=0){
			cout<<minx<<" "<<miny<<"\n";
			continue;
		}
		cout<<(maxx-minx)/p1+1<<" "<<minx<<" "<<miny<<" "<<maxx<<" "<<maxy<<"\n";
	}
	return 0;
}

样例没过,求条

2025/7/28 09:39
加载中...