#P16817. [蓝桥杯 2026 国 Python B] 稳定史莱姆

    ID: 19158 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>模拟数学2026蓝桥杯国赛

[蓝桥杯 2026 国 Python B] 稳定史莱姆

Problem Description

Xiao Lan raises NN slimes. The initial weight of the ii-th slime is aia_i.

It is known that a slime whose weight is not a multiple of 33 is in a stable state, while a slime whose weight is a multiple of 33 is in an unstable state. To make all slimes stable, Xiao Lan can cast a splitting spell.

Each time he casts the spell, Xiao Lan may choose a value WW that is divisible by 33. When the spell takes effect, all slimes whose current weight is exactly WW will split at the same time. Each such slime becomes three slimes of weight W/3W/3.

Now, please compute the minimum number of spells Xiao Lan needs to cast so that all slimes become stable.

Input Format

The first line contains an integer NN, representing the initial number of slimes.

The second line contains NN positive integers a1,a2,…,aNa_1, a_2, \dots, a_N, representing the initial weights of the slimes.

Output Format

Output one integer, representing the minimum number of spell casts needed to make all slimes stable.

5
18 7 9 6 3
4

Hint

Sample Explanation

The initial weight sequence is: [18,7,9,6,3][18, 7, 9, 6, 3].

  1. Choose W=18W = 18: the only 1818 in the sequence splits, and the sequence becomes [6,6,6,7,9,6,3][6, 6, 6, 7, 9, 6, 3].
  2. Choose W=9W = 9: the only 99 in the sequence splits, and the sequence becomes [6,6,6,7,3,3,3,6,3][6, 6, 6, 7, 3, 3, 3, 6, 3].
  3. Choose W=6W = 6: now there are four 66's in the sequence, and they all split at the same time into 22 (reaching a stable state), and the sequence becomes [2,2,2,2,2,2,2,2,7,3,3,3,2,2,2,3][2, 2, 2, 2, 2, 2, 2, 2, 7, 3, 3, 3, 2, 2, 2, 3].
  4. Choose W=3W = 3: now all 33's in the sequence split at the same time into 11 (reaching a stable state).

After 44 spells, none of the slimes' weights is divisible by 33, and all of them have reached a stable state.

Constraints

For 30%30\% of the testdata: 1≤N≤10001 \le N \le 1000, 1≤ai≤1051 \le a_i \le 10^5.

For all testdata: 1≤N≤1061 \le N \le 10^6, 1≤ai≤1091 \le a_i \le 10^9.

Translated by ChatGPT 5