aboutsummaryrefslogtreecommitdiff
path: root/18_additional_problems_ii/bouncing_ball_steps_3215.cpp
blob: b09bba222774b32d23a41173c064b958aaaf463b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <algorithm>
#include <iostream>
#include <numeric>
#include <tuple>

typedef long long ll;

std::tuple<ll, ll, ll> f(ll n, ll m, ll k) {
	n--; m--;
	ll am{k % (2*n)}, ad{k / n}, bm{k % (2*m)}, bd{k / m};
	if (am > n) am = n - (am-n);
	if (bm > m) bm = m - (bm-m);
	return {am, bm, ad+bd-k/std::lcm(n, m)};
}

int main() {
	ll t, n, m, k;
	std::cin >> t;
	for (ll i = 0; i < t; i++) {
		std::cin >> n >> m >> k;
		auto [a, b, c] = f(n, m, k);
		std::cout << a+1 << " " << b+1 << " " << c << "\n";
	}
}

Generated with cgit - Back to sebastiano.tronto.net