跳到正文

个人记录

debug

zengzhibo123约 1 分钟
原文
文章信息与版本

文章信息

发布
2026年10月5日
收录
2026年10月5日
更新
2026年11月8日
篇幅
约 1 分钟

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>
#define int __int128
#define ll long long
using namespace std;
ll a,b,c;
int x,y;
void exgcd(int a,int b)
{
	if(b==0)
	{
		x=1;y=0;
		return;
	}
	exgcd(b,a%b);
	int x0=x,y0=y;
	x=y0;
	y=x0-(a/b)*y0;
	return;
}
void work(){
	cin>>a>>b>>c;
	x=0;y=0;
	int d=__gcd(a,b);
	if(c%d!=0)
	{
		cout<<"NO"<<endl;
		return;
	}
	exgcd(a,b);
	c/=d;
	x*=c;y*=c;
	int k=floor(x*d*1.0/b);
	cout<<(ll)(x-b*k/d)<<" "<<(ll)(y+a*k/d)<<endl;
}
signed main(){
	freopen("exgcd.in","r",stdin);
	freopen("exgcd.out","w",stdout);
	ll t;cin>>t;
	while(t--) work();
}
原文