#include #include #include #include #define TEST //X Y Z unsigned int getSticksForArea(const unsigned int& x, const unsigned int& y, const unsigned int& z) { return x * (y + 1) * (z + 1) + y * (x + 1) * (z + 1) + z * (x + 1) * (y + 1); } //12 -> 8 -> 8 -> 8 .... (12 - 4 * (neighbors_count - 1)) // 2x2x1 = 2*3*3*3 = 54 //12+(12-4)+( int main() { unsigned int number; #ifdef TEST unsigned int testnum = 47; number = testnum; #else std::cin >> number; #endif // TEST unsigned int x = 0, y = 0, z = 0; //optimize = cube form unsigned int cube_edge = std::cbrt(number); x = cube_edge; y = cube_edge; z = cube_edge; //adding remaining cubes //remaining auto remain = number - x * y * z; //adding full areas x += remain / (x * y); //computing sticks unsigned int res_cube = getSticksForArea(x, y, z); //update remain number(after adding ares) //now remain 100% less than z * y remain = number - x * y * z; //std::cout << getSticksForArea(3,2,3); //1-8 //2-4 //3-2 //>=4 - 0 //number of neighbors std::vector add(remain); //i*y+j for (int i = 0; i < y; i++) { if (remain == 0) { break; } for (int j = 0; j < z; j++) { if (remain == 0) { break; } remain -= 1; unsigned int num_neighbor = 1; if (j - 1 >= 0) { num_neighbor++; } if (i - 1 >= 0) { num_neighbor++; } add[i * y + j] = num_neighbor; } } unsigned int sticks_to_add = 0; for (auto& a : add) { switch (a) { case(1): sticks_to_add += 8; break; case(2): sticks_to_add += 4; break; case(3): sticks_to_add += 2; default: break; } } std::cout << res_cube + sticks_to_add; return 0; }