#B3994. Perimeter and Area of a Square Pattern
Perimeter and Area of a Square Pattern
Perimeter and Area of a Square Pattern
Consider a pattern formed by squares placed side by side. The first square has side length , the second square has side length , and so on until the -th square which has side length . All squares are arranged in a row with their bottom sides aligned. They touch each other along adjacent vertical sides, so that no two squares overlap.
Determine the perimeter and the area of the union of these squares.
The area is given by the sum of the areas of the individual squares: [ A = 1^2 + 2^2 + \cdots + n^2 = \frac{n(n+1)(2n+1)}{6}. ]
To compute the perimeter, observe that the bottom side is a single horizontal segment of length (\sum_{i=1}^{n} i = \frac{n(n+1)}{2}), the top boundary consists of the top edges of each square (which sum to the same value), and the vertical sides include the left side of the first square, the right side of the last square, and the vertical differences between consecutive squares. In fact, it can be shown that the total perimeter is: [ P = n^2 + 3n. ]
You are given the integer (n) as input. Your task is to compute (P) and (A) respectively and output them separated by a space.
inputFormat
The input consists of a single integer (n) ((1 \leq n \leq 10^5)), which indicates the number of squares.
outputFormat
Output two integers separated by a space. The first integer is the perimeter (P = n^2 + 3n) of the pattern, and the second integer is the area (A = \frac{n(n+1)(2n+1)}{6}) of the pattern.
sample
1
4 1