Submission

Status:

PPPPPPPPPPPPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: ChanakanStudy

Problemset: มุมขวาบน

Language: cpp

Time: 0.081 second

Submitted On: 2026-10-12 00:47:45

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <numeric>
#include <iomanip>
using namespace std;
using ll = long long;

ll findtopright(ll n) {
    if(n == 1) {
        return 1;
    }
    else {
        return findtopright(n-1) + 6 + ((n-2)*8);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll pos = 0;
    int count = 1;
    while(pos < n) {
        pos = findtopright(count);
        count++;
    }
    if(pos - n == 2) {
        cout << "Cannot find top-right corner.";
    }
    else if (pos - n == 1) {
        cout << n;
    }
    else if(pos - n == 0) {
        cout << pos;
    }
    else if (pos - n > 2) {
        cout << findtopright(count-2);
    }
    return 0;
}