eolymp
bolt
Try our new interface for solving problems
Məsələlər

Iterated Difference

Iterated Difference

You are given a list of \textbf{N} non-negative integers \textbf{a(1)}, \textbf{a(2)}, ... , \textbf{a(N)}. You replace the given list by a new list: the \textbf{k}-th entry of the new list is the absolute value of \textbf{a(k) - a(k+1)}, wrapping around at the end of the list (the \textbf{k}-th entry of the new list is the absolute value of \textbf{a(N) - a(1)}). How many iterations of this replacement are needed to arrive at a list in which every entry is the same integer? For example, let \textbf{N = 4} and start with the list (\textbf{0 2 5 11}). The successive iterations are: \textbf{2 3 6 11 1 3 5 9 2 2 4 8 0 2 4 6 2 2 2 6 0 0 4 4 0 4 0 4 4 4 4 4} Thus, \textbf{8} iterations are needed in this example. \InputFile The input will contain data for a number of test cases. For each case, there will be two lines of input. The first line will contain the integer \textbf{N} (\textbf{2} ≤ \textbf{N} ≤ \textbf{20}), the number of entries in the list. The second line will contain the list of integers, separated by one blank space. End of input will be indicated by \textbf{N = 0}. \OutputFile For each case, there will be one line of output, specifying the case number and the number of iterations, in the format shown in the sample output. If the list does not attain the desired form after \textbf{1000} iterations, print '\textbf{not attained}'.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
4
0 2 5 11
5
0 2 5 11 3
4
300 8600 9000 4000
16
12 20 3 7 8 10 44 50 12 200 300 7 8 10 44 50
3
1 1 1
4
0 4 0 4
0
Çıxış verilənləri #1
Case 1: 8 iterations
Case 2: not attained
Case 3: 3 iterations
Case 4: 50 iterations
Case 5: 0 iterations
Case 6: 1 iterations
Mənbə 2011 Rocky Mountain Regional ACM Contest Information