What is the largest complete square grid under a tile budget?
isqrt returns the floor of a nonnegative integer's square root without converting the budget to floating point.
Python example and interpretation
Seventeen tiles fit a 4×4 grid with one left over. Convert a memory budget to a tile budget first if tiles have different costs.
import math
n=17
side=math.isqrt(n)
[side,n-side**2]Result [4, 1]
中文
已知图块预算时,最大完整正方形网格有多大?
isqrt 返回非负整数平方根的向下取整结果,计算无需将整数转换为浮点值。
Python 算例与适用条件
17 个图块可放下 4×4 网格并余一块。若每个格子的内存成本不同,应先换算预算再选边长。
import math
n=17
side=math.isqrt(n)
[side,n-side**2]结果 [4, 1]