Chandan gave his son a cube with side N. The N X N X N cube is made up of small 1 X 1 X 1 cubes.
Chandan's son is extremely notorious just like him. So he dropped the cube inside a tank filled with Coke. The cube got totally immersed in that tank. His son was somehow able to take out the cube from the tank. But sooner his son realized that the cube had gone all dirty because of the coke. Since Chandan did not like dirty stuffs so his son decided to scrap off all the smaller cubes that got dirty in the process. A cube that had coke on any one of its six faces was considered to be dirty and scrapped off. After completing this cumbersome part his son decided to calculate volume of the scrapped off material. Since Chandan's son is weak in maths he is unable to do it alone.
Help him in calculating the required volume.
Example:
Input: n = 3
Output: 26
Approach
C++
#include <bits/stdc++.h>using namespace std;long long cubeChange(long long n){long long res;if (n == 1)return 1;else{res = 6 * n * n - 12 * n + 8;return res;}}int main(){long long n = 3;cout << cubeChange(n) << "\n";return 0;}
No comments:
Post a Comment