1954.cpp (460B)
1 class Solution { 2 public: 3 long long minimumPerimeter(const long long neededApples) const { 4 long long low = 1, high = 100000; 5 while (low < high) { 6 const long long mid = (low + high) / 2; 7 const long long count = 4 * mid * mid * mid + 6 * mid * mid + 2 * mid; 8 if (count >= neededApples) 9 high = mid; 10 else 11 low = mid + 1; 12 } 13 return low * 8; 14 } 15 };