nikunjsoni

1954

Aug 2nd, 2021
828
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     long long minimumPerimeter(long long neededApples) {
  4.         long long i=1;
  5.         for(;neededApples>0;i++){
  6.             neededApples-=3*i*4; // i*4+2*i*4
  7.             neededApples-=(((2*i)*(2*i-1))/2-(i*(i+1))/2)*8; // summation using (n*(n+1))/2
  8.         }
  9.         return (i-1)*8;
  10.     }
  11. };
RAW Paste Data