#P12340. Count 'A' in the LANQIAO Flag
Count 'A' in the LANQIAO Flag
Count 'A' in the LANQIAO Flag
Little Blue wants to create a flag by cutting out letters from a LANQIAO pattern. The pattern is a rectangle with height h and width w. When h = 5 and w = 10, the pattern is:
LANQIAOLAN ANQIAOLANQ NQIAOLANQI QIAOLANQIA IAOLANQIAO
The pattern is generated as follows:
- The first row is filled by repeating the string
LANQIAO
. - For every subsequent row, the string is cyclically shifted to the left by one character relative to the previous row.
Formally, let the base pattern be \(P = \texttt{LANQIAO}\) with length \(L = 7\). For row \(i\) (starting from \(0\)), the row is constructed by writing the infinite sequence \(P\,P\,P\,...\) starting from index \(i \bmod L\), then taking the first \(w\) characters. Your task is to count the total number of occurrences of the letter A
in the entire \(h \times w\) pattern.
Input format: Two integers \(h\) and \(w\).
Output format: A single integer representing the total count of letter A
in the grid.
inputFormat
The first and only line of the input contains two integers \(h\) and \(w\), where \(h\) is the height and \(w\) is the width of the pattern.
outputFormat
Output a single integer: the number of occurrences of 'A' in the generated \(h \times w\) grid.
sample
5 10
14