#P10900. Mathematical Poetry

    ID: 12945 Type: Default 1000ms 256MiB

Mathematical Poetry

Mathematical Poetry

In the eyes of a poet, numbers are the rhythm of life and a form of poetic expression. Contemporary top poet and mathematician Xiao Lan, also known as the "Mathematical Poet," sees beauty in the fusion of cold numbers and abstract sentiment. One day, Xiao Lan observed a sequence of n numbers: \(a_1, a_2, \cdots, a_n\), each shining with its own luster.

He realized that if a number can be represented as the sum of at least two consecutive positive integers, it carries poetic charm. For example, the number \(6\) is poetic because it can be represented as \(1+2+3\), while \(8\) lacks this charm since it cannot be expressed in such a manner.

To ensure that every number in front of him exudes poetry, Xiao Lan decides to remove some numbers from the sequence. Your task is to calculate the minimum number of numbers that need to be removed so that every remaining number is poetic.

Mathematical Note: A positive integer \(x\) (with \(x > 0\)) can be expressed as the sum of two or more consecutive positive integers if and only if it is not a power of \(2\). In other words, if \(x\) is a power of \(2\), it lacks the needed representation.

inputFormat

The first line contains a single integer \(n\) representing the number of numbers.

The second line contains \(n\) space-separated positive integers \(a_1, a_2, \cdots, a_n\).

outputFormat

Output a single integer representing the minimum number of numbers to remove so that every remaining number can be expressed as the sum of at least two consecutive positive integers.

sample

5
6 8 9 16 15
2

</p>