F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Shorten the array

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 396    Accepted Submission(s): 143


Problem Description
Alice has an array $a$. The array has $N$ positive numbers. She thinks the array is too long, so she wants to shorten the array. She decides to shorten the array via the following operation: every time she will choose an index $i$ $(1 \le i<n)$ which $a_i > 0$ and $a_{i+1} > 0$. She will delete $a_i$ and $a_{i+1}$ and use $(a_i\operatorname{mod} a_{i+1})$ or $(a_{i+1}\operatorname{mod} a_{i})$ to replace them.

For example, for array $[3, 2, 4, 5]$, if Alice choose $i=2$, she can change the array to $[3, 2, 5]$ or $[3, 0, 5]$. Alice wants you to tell her the shortest possible length of the array after several options.
 

Input
The first line contains a single integer $T$ $(1 \le T \le 10)$, indicating the number of test cases.

For each test cases:

The first line contains one integer $N$ $(2 \le N \le 10^6)$, indicating the size of the array.

The next line contains $N$ integers $a_i$ $(a_i \le 10^{9})$, representing the array.
 

Output
Output $T$ lines.

The $i$-th line contains a single integer, representing the answer of $i$-th test case.
 

Sample Input
2 4 1 1 1 1 4 2 3 4 5
 

Sample Output
2 1
 

Hint

For the first sample, Alice first choose $i=1$ to change the array to $[0, 1, 1]$, then choose $i=2$ to change the array to $[0, 0]$, which is the best result she can reach.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-12 00:47:52, Gzip enabled