#C11460. Lexicographically Smallest String with Two Distinct Characters
Lexicographically Smallest String with Two Distinct Characters
Lexicographically Smallest String with Two Distinct Characters
Given an integer \(N\), your task is to construct the lexicographically smallest string of length \(N\) that contains exactly two different characters: a
and b
. Both characters must appear at least once. To achieve the lexicographically smallest string, you should use the character a
as many times as possible (specifically \(N-1\) times) and then append the character b
once at the end.
If \(N < 2\), it is impossible to form such a string, so your program should output the error message: N must be at least 2 to satisfy the constraint of having exactly two different characters.
inputFormat
The input consists of a single integer \(N\) provided via standard input. \(N\) represents the length of the string to be formed.
outputFormat
Output the lexicographically smallest string of length \(N\) that contains exactly two distinct characters (a
and b
). If \(N < 2\), output the following error message:
N must be at least 2 to satisfy the constraint of having exactly two different characters.
2
ab