Ducci序列 Ducci Sequence

题意翻译

对于一个 $n$ 元组($a_1,a_2,\cdots,a_n$),可以对每个数求出它和下一个数的差的绝对值,得到一个新的 $n$ 元组($|a_1-a_2|,|a_2-a_3|,\cdots,|a_n-a_1|$)。重复这个过程,得到的序列称为 Ducci 序列,例如: $$(8,11,2,7)\rightarrow(3,9,5,1)\rightarrow(6,4,4,2)\rightarrow(2,0,2,4)\rightarrow(2,2,2,2)\rightarrow(0,0,0,0)$$ 也有的 Ducci 序列最终会循环。输入 $n$ 元组($3\le n\le15$),你的任务是判断它最终会变成0还是会循环。输入保证最多 $1000$ 步就会变成 $0$ 或循环。 输入格式: 第一行是一个整数 $T$,表示有 $T$ 组数据。 每组数据第一行是一个整数 $n(3\le n\le15)$,表示 Ducci 序列的长度。第二行有 $n$ 个数 $a_i(0\le a_i\le1000)$。 输出格式: 如果最终会循环,输出 `LOOP`,否则输出 `ZERO`。 感谢 @andyli 提供的翻译

题目描述

[problemUrl]: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=448&page=show_problem&problem=4469 [PDF](https://uva.onlinejudge.org/external/15/p1594.pdf)

输入输出格式

输入格式


输出格式


输入输出样例

输入样例 #1

4
4
8 11 2 7
5
4 2 0 2 0
7
0 0 0 0 0 0 0
6
1 2 3 1 2 3

输出样例 #1

ZERO
LOOP
ZERO
LOOP