#K78462. Unique K-Length Strings Without Adjacent Duplicate Characters
Unique K-Length Strings Without Adjacent Duplicate Characters
Unique K-Length Strings Without Adjacent Duplicate Characters
You are given an integer K
which represents the length of strings to be formed using the 4 characters {a, b, c, d}
. Your task is to compute the number of unique K
-length strings such that no two adjacent characters are the same.
The answer can be derived using the formula:
\(4 \times 3^{K-1}\) for \(K \geq 1\).
For example:
- When
K = 1
, the number of strings is4
. - When
K = 2
, the number of strings is12
. - When
K = 3
, the number of strings is36
.
Write a program that reads the integer K
from standard input and outputs the number of valid strings to standard output.
inputFormat
The input consists of a single integer K
(where K ≥ 1
) provided through standard input.
outputFormat
Output a single integer representing the number of unique K
-length strings that can be formed under the given conditions.
1
4
</p>