185372025-10-26 12:20:22ubormaciFagyasztócpp17Wrong answer 0/753ms556 KiB
#include <iostream>
#include <algorithm> // for sort, mainly
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <array>
#include <string>
#include <cstdio>
#include <iterator>
#include <unordered_set>
#include <cstdint> // for int64_t, int32_t, etc
#include <queue>
#include <stack>
#include <deque>
#include <numeric> // gcd, lcm
#include <fstream>
#include <bitset> // for bitset
#include <iomanip>
#include <cassert> // for set with custom ordering
#include <type_traits> // for set with custom ordering
#include <utility> // for swap, forward, etc
using namespace std;

#pragma GCC optimize("O2")
// #pragma GCC optimize("O1","O2","O3","Ofast","unroll-loops")
// #pragma GCC target("sse","sse2","sse3","sse4.1","sse4.2","avx","avx2","fma")

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

/*

notes:

int64_t
stoi(string s) -> string to int
to_string() -> int (or else) to string

vector declaration:
vector<ll> v(n, 0)
vector<vector<ll>> v(n, vector<ll>(n, 0));

{if statement} ? {truth value} : {false value}

#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

std::lcm(ll a, ll b), std::gcd(int a, int b)

cout << fixed << setprecision(n);

set with custom ordering
set<ll, decltype(&cmp)> qu(cmp);

*/

typedef int64_t ll;

ll extendedeuclid(ll a, ll b, ll &x, ll &y) {

	if(b == 0) {
		x = 1;
		y = 0;
		return a;
	}

	ll x1, y1;
	ll d = extendedeuclid(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * (a / b);
	return d;
}	

pair<ll,ll> solve1(ll h, ll a, ll b) {

	// a * x + b * y = c
	// oldest problem in the book
	// and I'm still shit at it but let's not get so hasty

	// szoval
	// standard extended euclidean algorithm megoldja a * x + b * y = gcd(x, y)
	// es erre ad egy a, b erteket
	// ha c mod gcd = 0, akkor egyszeruen vesszik c / g es beszorozzuk vele az x/y-t

	ll g = gcd(a, b);
	if(h % g != 0) {
		return {0, 0};
	}

	ll x0, y0;
	extendedeuclid(a, b, x0, y0);
	x0 *= h / g;
	y0 *= h / g;

	ll k = 0;
	while(1) {

		ll x = x0 + k * (b/g);
		ll y = y0 - k * (a/g);

		if(x >= 0 && y >= 0) {
			return {x, y};
		}
		k++;
	}

	return {0, 0};
}


pair<ll,ll> solve2(ll h, ll a, ll b) {

	// a * x + b * y = c
	// oldest problem in the book
	// and I'm still shit at it but let's not get so hasty

	// szoval
	// standard extended euclidean algorithm megoldja a * x + b * y = gcd(x, y)
	// es erre ad egy a, b erteket
	// ha c mod gcd = 0, akkor egyszeruen vesszik c / g es beszorozzuk vele az x/y-t

	if(h == a) {
		return {1, 0};
	}

	ll g = gcd(a, b);
	if(h % g != 0) {
		return {0, 0};
	}

	ll x0, y0;
	extendedeuclid(a, b, x0, y0);
	x0 *= h / g;
	y0 *= h / g;

	if(x0 >= 0 && y0 >= 0) {
		return {x0, y0};
	}

	// x = x0 + k * (b/g)
	// y = y0 - k * (a/g)

	/*
	if(x0 < 0 && y0 >= 0) {

		// tehat maximalisan noveljuk az x-et
		// vagyis y-t a leheto legkisebbig levisszuk
		//  y = y0 - k * (a/g)
		// y0 = k * (a/g)
		// k = (y0) / (a/g)

		ll k = y0 / (a/g);

		ll x = x0 + k * (b/g);
		ll y = y0 - k * (a/g);

		return {x, y};
	}

	if(x0 >= 0 && y0 < 0) {

		// x = x0 + k * (b/g)
		// x0 = -k * (b/g)
		// k = -x0 / (b/g)

		ll k = -x0 / (b/g);

		ll x = x0 + k * (b/g);
		ll y = y0 - k * (a/g);

		return {x, y};

	}
	*/

	// x > 0
	// x0 + k * (b/g) > 0
	// k * (b/g) > -x0
	// k > -x0 / (b/g)
	
	// y0 > 0
	// y0 - k * (a/g) > 0
	// -k * (a/g) > -y0
	// k < y0 / (a/g)

	ll kmin = -x0 / (b/g);
	ll kmax = y0 / (a/g);
 
	//cerr << "\nkmin=" << kmin;
	//cerr << "\nkmax=" << kmax;

	if(kmin <= kmax) {
		return {x0 + kmax * (b/g), y0 - kmax * (a/g)};
	}

	return {0, 0};
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);

	/*
	for(ll h = 1; h <= 10; h++) {
		for(ll a = 1; a <= 10; a++) {
			for(ll b = 1; b <= 10; b++) {

				cerr << "\n" << h << " " << a << " " << b;

				auto ans1 = solve1(h, a, b);
				auto ans2 = solve2(h, a, b);

				if(ans1 != ans2) {
					cout << "\nPROBLEM " << ans1 << " " << ans2;
				}

			}
		}
	}
	*/

	ll h, a, b;
	cin >> h >> a >> b;

	auto ans = solve2(h, a, b);

	cout << ans.first << " " << ans.second; 	

	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer1ms316 KiB
subtask20/10
2Wrong answer2ms316 KiB
3Wrong answer1ms316 KiB
4Wrong answer1ms316 KiB
5Wrong answer1ms316 KiB
6Wrong answer1ms316 KiB
7Wrong answer1ms316 KiB
8Wrong answer1ms316 KiB
9Wrong answer1ms388 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms316 KiB
subtask30/20
12Wrong answer1ms316 KiB
13Wrong answer1ms316 KiB
14Wrong answer1ms316 KiB
15Wrong answer1ms316 KiB
16Wrong answer1ms512 KiB
17Wrong answer1ms508 KiB
18Wrong answer1ms508 KiB
19Wrong answer1ms512 KiB
20Wrong answer1ms316 KiB
21Wrong answer1ms316 KiB
22Wrong answer1ms316 KiB
23Wrong answer1ms316 KiB
24Wrong answer1ms512 KiB
25Wrong answer1ms316 KiB
26Wrong answer1ms508 KiB
27Wrong answer1ms316 KiB
28Wrong answer1ms532 KiB
29Wrong answer1ms500 KiB
30Wrong answer1ms316 KiB
31Wrong answer1ms316 KiB
subtask40/15
32Wrong answer1ms376 KiB
33Wrong answer1ms316 KiB
34Wrong answer1ms316 KiB
35Wrong answer1ms316 KiB
36Wrong answer1ms316 KiB
37Wrong answer1ms508 KiB
38Wrong answer1ms316 KiB
39Wrong answer1ms316 KiB
40Wrong answer1ms316 KiB
41Wrong answer1ms316 KiB
42Wrong answer1ms316 KiB
43Wrong answer1ms316 KiB
44Wrong answer1ms316 KiB
45Wrong answer1ms316 KiB
46Wrong answer3ms548 KiB
subtask50/15
47Wrong answer1ms316 KiB
48Wrong answer1ms316 KiB
49Wrong answer1ms316 KiB
50Wrong answer1ms316 KiB
51Wrong answer1ms316 KiB
52Wrong answer1ms316 KiB
53Wrong answer1ms316 KiB
54Wrong answer1ms316 KiB
55Wrong answer1ms508 KiB
56Wrong answer1ms500 KiB
57Wrong answer1ms316 KiB
58Wrong answer1ms352 KiB
59Wrong answer1ms316 KiB
60Wrong answer1ms316 KiB
61Wrong answer1ms556 KiB
subtask60/15
62Wrong answer1ms316 KiB
63Wrong answer1ms316 KiB
64Wrong answer1ms316 KiB
65Wrong answer1ms500 KiB
66Wrong answer1ms316 KiB
67Wrong answer1ms316 KiB
68Wrong answer1ms316 KiB
69Wrong answer1ms316 KiB
70Wrong answer1ms316 KiB
71Wrong answer1ms316 KiB
72Wrong answer1ms316 KiB
73Wrong answer1ms316 KiB
74Wrong answer1ms316 KiB
75Wrong answer1ms316 KiB
76Wrong answer1ms316 KiB