Submission

Status:

----PP------PPP-----

Subtask/Task Score:

25/100

Score: 25

User: peilin

Problemset: มุมขวาบน

Language: c

Time: 0.002 second

Submitted On: 2025-10-12 17:56:31

#include <stdio.h>
#include <math.h>

int main() {
    long long n;
    scanf("%lld", &n);

    if (n == 1) {
        printf("1\n");
        return 0;
    }

    long long k = ceil(sqrt((double)n));
    if (k % 2 == 0) k++;

    long long top_right = k * k - (k - 1);
    long long prev_square = (k - 2) * (k - 2);

    if (n <= prev_square)
        top_right = (k - 2) * (k - 2) - ((k - 2) - 1);

    if (n == top_right - 1)
        printf("Cannot find top-right corner.\n");
    else
        printf("%lld\n", top_right);

    return 0;
}