What it is saying is that a brick is a cube, and has sides one match long.

So a single brick requires 12 matches.

If you put two bricks together, they can share matches: one needs 12, the other needs 4 less.

For three or more bricks, each end needs 12 matches, and each non-end brick needs only 4.

So what you have to do is write a function that takes a number of bricks N and returns the number of matches needed to make it: 12 for N == 1, 12 + 8 for N == 2, and 12 + 4 * (N-2) + 12 for values of N greater than 2.

Give it a try: it's not a complex problem. If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

16,018,353 members

12+(n-1)*8

in a function and return that calculated value from the function, using C++ or Java, based on your tags.