#include<iostream> usingnamespace std; intmain(){ int n, a = 1, b, c, nn; cin >> n; b = n; c = n; while (a * a != b) { while (a * a < b) {a++;} if (a * a != b) {a = 1;b--;} } while (a * a != c) { while (a * a < c) {a++;} if (a * a != c) {a = 1;c++;} } if ((c - n) > (n - b)) { cout << b; } else { cout << c; } return0; }
Python
1 2 3 4 5
import math
m = int(math.sqrt(int(input()))) x, y = m ** 2, (m + 1) ** 2 print(x if m - x < y - m else y)