AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

FPC25-027.Characterithmetic

Easy · 3 s · 256 MB

  • icpc
  • fpc
  • 2025

While solving one problem after the other in your favourite programming contest (hopefully, the one you are at right now!), you are suddenly faced with an Alternative Arithmetic Problem for the Jury's Entertainment. In this problem, you are not calculating with numbers, but with strings.

For some arbitrary string ttt and integer kkk, we define t⊙kt\odot kt⊙k (ttt times kkk) to be the string ttt concatenated kkk times. If ttt can be written as t′⊙kt' \odot kt′⊙k for some other string t′t't′, we say that kkk is a divisor of ttt. For example, the divisors of the string “abababab” are 111, 222, and 444, because this string can be written as either “abababab”⊙1\text{``\texttt{abababab}''} \odot 1“abababab”⊙1, or “abab”⊙2\text{``\texttt{abab}''} \odot 2“abab”⊙2, or “ab”⊙4\text{``\texttt{ab}''} \odot 4“ab”⊙4. Finally, we say that a string is indivisible if its only divisor is 111: for example, the string “abc” is indivisible.

You are given a string sss of length nnn, that contains only the characters ‘a’, ‘b’, and ‘c’. For each divisor ddd of nnn, you need to change some of the characters (to either ‘a’, ‘b’, or ‘c’), so that the largest divisor of sss becomes ddd. Find the minimum number of characters that need to be changed in order to make this true.

As an example, consider the first sample input. There are three answers, one for each of the divisors of 444:

• To make the largest divisor of “acac” be 111, we need to make sure that 222 is not a divisor. We can change any character to make the string indivisible, e.g. “bcac”.

• The largest divisor of “acac” is already 222, so no characters need to change and the answer is 000.

• To make the largest divisor 444, we need to make all characters equal. To do this, 222 characters need to be changed, yielding either “aaaa” or “cccc”.

Giriş formatı

The input consists of:

• One line with an integer nnn (2≤n≤1052 \leq n \leq 10^52≤n≤105), the length of your string.

• One line with a string sss of length nnn, consisting only of characters ‘a’, ‘b’, and ‘c’.

Çıxış formatı

For each divisor ddd of nnn, in increasing order, output the minimum number of characters that you need to change to make the largest divisor of sss equal to ddd.

Qeyd

Source: Freshmen Programming Contest 2025 · License: CC BY-SA 4.0 · Original: https://fpc.wisv.ch · Statement adapted for AlgoLens and shared under the same license. · 45 of the 165 original test cases (the largest) are omitted here to keep the problem lightweight.

Nümunələr

Giriş #1

4
acac

Çıxış #1

1 0 2

Giriş #2

6
abccba

Çıxış #2

0 2 4 4