跳到正文

题解

U737614 题解

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

文章信息

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

版本

  1. v1当前
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int exgcd(int a, int b, int &x, int &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	int d = exgcd(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
void work(){
	int a, b, x, y, d;
	cin >> a >> b;
	d = exgcd(a, b, x, y);
	cout << d << "\n" << x << " " << y << "\n";
	cout << (x % (b / d) + b / d) % (b / d);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	while(T--) work();
	return 0;
}
原文