Karaz (Callatz) conjecture has been given a description in 1001. In this subject, the situation is slightly more complicated.
When we verify Karaz conjecture, in order to avoid repetition, we can record each number that is encountered in the recursive process. For example, when validating the n=3, we need to calculate 3, 5, 8, 4, 2, 1, then when we verify the n=5, 8, 4, 2, we can directly determine the authenticity of Karaz conjecture, and do not need to repeat the calculation, because this 4 number has been in the validation of 3, we call 5, 8, 4, 2 is the number that is 3 "covered". We call a number N in a series A "key number" if n cannot be overridden by other numbers in the sequence.
Now given a series of numbers to be validated, we just need to validate a few of the key numbers, so we don't have to re-validate the remaining numbers. Your task is to find these key numbers and output them in order from large to small.
input Format: each test input contains 1 test cases, the 1th line gives a positive integer k (<100), and line 2nd gives the value of k distinct positive integer n (1<n<=100), separated by a space between the numbers.
output format: the output of each test case occupies one row, and the key numbers are output in order from large to small. The number is separated by 1 spaces, but there is no space after the last digit in a row.
Input Sample:
63 5 6 7 8 11
Sample output:
7 6
Exercises
Enumeration ideas for reference primes, using arrays for tagging,
First set a large array b[n] all zeros, and then follow the test instructions Karaz guess the rule operation, in the Loop NUM/2, (3*num+1)/2 These "procedure number" marked 1
Array A[k] is a read-in array, verifying that the "critical number" method in A[k] is looping through and outputting the value of the corresponding array a[i] that conforms to if (b[a[i] = = 0),
Although the input sample given in the topic is in ascending order, it is not explicitly stated in the problem, so it is still possible to construct an array c[] to do it again.
1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4 #defineN 100015 6 intcmpConst void*a,Const void*b)7 {8 return*(int*) b-* (int*) A;9 }Ten One intMain () A { - - intK; the intB[n]; -scanf"%d",&K); - intA[k]; - for(intI=0; i<k;i++) +scanf"%d",&A[i]); - + for(inti =0; I < k;i++) A { at intTMP =A[i]; - while(tmp!=1) - { - if(tmp%2==0) -TMP/=2; - Else inTMP = (3*tmp+1)/2; -B[TMP] =1; to } + } - intnum =0; the intC[k]; * for(intI=0; i<k;i++) $C[i] =0;Panax Notoginseng for(inti=k-1; i>=0; i--) - { the if(!B[a[i]]) +c[num++] =A[i]; A } the //printf ("num:%d\n", num); +Qsort (C,num,sizeof(int), CMP); - for(intI=0; i<num;i++) $ { $ if(I! = (num-1)) - { -printf"%d", C[i]); the } - Else Wuyiprintf"%d", C[i]); the } - return 0; Wu}
Continue (3n+1) conjecture