Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define endl '\n'
- #define sz(x) int(x.size())
- #define all(x) x.begin(), x.end()
- int main() {
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- ll sz, p;
- while (cin >> sz >> p, sz || p) {
- ll x, y;
- x = y = (sz + 1) / 2;
- auto calc = [&](ll rot) {
- return 1 + 2 * rot * rot + 2 * (rot + 1) * (rot);
- };
- auto BS = [&]() {
- ll l = 0, r = 1;
- while (calc(r) <= p) r *= 2;
- ll best = 0;
- while (l <= r) { // 111111111100000000000
- ll mid = l + (r - l) / 2;
- (calc(mid) <= p ? l = mid + 1, best = mid : r = mid - 1);
- }
- return best;
- };
- int rot = BS();
- y -= rot;
- x += rot;
- ll sum = calc(rot);
- if (sum < p) {
- int con = rot * 2 + 1;
- vector<ll> nums = {con, con, con + 1, con + 1};
- int i = 0;
- for (i = 0; i < 4 && sum + nums[i] <= p; i++) {
- sum += nums[i];
- if (i == 0) y += nums[i];
- if (i == 1) x -= nums[i];
- if (i == 2) y -= nums[i];
- if (i == 3) x += nums[i];
- }
- if (sum < p) {
- if (i == 0) y += p - sum;
- if (i == 1) x -= p - sum;
- if (i == 2) y -= p - sum;
- if (i == 3) x += p - sum;
- }
- }
- cout << "Line = " << y << ", column = " << x << ".\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement