Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <string>
- #include <chrono>
- #include <random>
- #include <cmath>
- #include <queue>
- #include <iomanip>
- using namespace std;
- using ll = long long;
- using ld = long double;
- mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
- bool maxi(ll &a, ll b) {
- if (b > a) {
- a = b;
- return true;
- }
- return false;
- }
- bool mini(ll &a, ll b) {
- if (b < a) {
- a = b;
- return true;
- }
- return false;
- }
- bool maxi(ld &a, ld b) {
- if (b > a) {
- a = b;
- return true;
- }
- return false;
- }
- bool mini(ld &a, ld b) {
- if (b < a) {
- a = b;
- return true;
- }
- return false;
- }
- ll n, m, q;
- vector <ll> vec;
- vector <bool> used;
- vector <ll> p, s, p2, s2;
- ll dsu_get(ll v) {
- return (p[v] == v ? v : p[v] = dsu_get(p[v]));
- }
- void dsu_unite(ll a, ll b) {
- a = dsu_get(a);
- b = dsu_get(b);
- if (s[a] < s[b]) {
- swap(a, b);
- }
- p[b] = a;
- s[a] += s[b];
- }
- ll dsu_get2(ll v) {
- return (p2[v] == v ? v : p2[v] = dsu_get(p2[v]));
- }
- void dsu_unite2(ll a, ll b) {
- a = dsu_get2(a);
- b = dsu_get2(b);
- if (s2[a] < s2[b]) {
- swap(a, b);
- }
- p2[b] = a;
- s2[a] += s2[b];
- }
- ll opa(ll n) {
- ll l = 0, r = n + 1;
- while (r - l > 1) {
- ll o = (l + r) / 2;
- if (o * o < n) {
- l = o;
- }
- else {
- r = o;
- }
- }
- return r;
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cin >> n;
- --n;
- ll block_num = n / 4 + 1;
- ll line_num = sqrt(block_num);
- while (line_num * line_num > block_num) {
- --line_num;
- }
- while (line_num * line_num < block_num) {
- ++line_num;
- }
- ll prev_line_num = line_num - 1;
- ll block_num_in_line = block_num - prev_line_num * prev_line_num;
- ll blockx, blocky;
- if (line_num % 2 == 0) {
- if (block_num_in_line > prev_line_num) {
- blocky = line_num;
- blockx = line_num - (block_num_in_line - line_num);
- }
- else {
- blocky = block_num_in_line;
- blockx = line_num;
- }
- }
- else {
- if (block_num_in_line > prev_line_num) {
- blockx = line_num;
- blocky = line_num - (block_num_in_line - line_num);
- }
- else {
- blockx = block_num_in_line;
- blocky = line_num;
- }
- }
- ll a = block_num * 4 - 3;
- ll b = block_num * 4 - 2;
- ll c = block_num * 4 - 1;
- ll d = block_num * 4;
- ++n;
- ll ansx, ansy;
- if (blockx == blocky) {
- if (n % 2 == 1) {
- if (n == min(a, c)) {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 1;
- }
- else {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 2;
- }
- }
- else {
- if (blockx % 2 == 1) {
- if (n == min(b, d)) {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 2;
- }
- else {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 1;
- }
- }
- else {
- if (n == min(b, d)) {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 1;
- }
- else {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 2;
- }
- }
- }
- }
- else if (blocky > blockx) {
- if (blocky % 2 == 0) {
- if (n == min(a, c)) {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 2;
- }
- else if (n == max(a, c)) {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 1;
- }
- else if (n == min(b, d)) {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 1;
- }
- else {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 2;
- }
- }
- else {
- if (n == max(a, c)) {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 2;
- }
- else if (n == min(a, c)) {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 1;
- }
- else if (n == max(b, d)) {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 1;
- }
- else {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 2;
- }
- }
- }
- else if (blocky < blockx) {
- if (blockx % 2 == 0) {
- if (n == min(a, c)) {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 1;
- }
- else if (n == max(a, c)) {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 2;
- }
- else if (n == min(b, d)) {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 1;
- }
- else {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 2;
- }
- }
- else {
- if (n == max(a, c)) {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 1;
- }
- else if (n == min(a, c)) {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 2;
- }
- else if (n == max(b, d)) {
- // cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
- ansx = (blockx - 1) * 2 + 2;
- ansy = (blocky - 1) * 2 + 1;
- }
- else {
- // cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
- ansx = (blockx - 1) * 2 + 1;
- ansy = (blocky - 1) * 2 + 2;
- }
- }
- }
- cout << ansy << ' ' << ansx;
- // cout << line_num << ' ' << block_num_in_line << ' ' << blockx << ' ' << blocky;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement