PAT b 1005. Continuation (3n+1) conjecture (25)

Source: Internet
Author: User

1005. Continuation (3n+1) conjecture (25) time limit MS Memory limit 65536 KB code length limit 8000 B

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


1 ImportJava.util.*;2 3  Public classMain4 {5     StaticScanner scan =NewScanner (system.in);6      Public Static voidMain (string[] args)7     {8         int[] flag =New int[110];9          for(inti = 0; I < 110; ++i)TenFlag[i] = 1; One         intK =scan.nextint (); A          while(k--! = 0) -         { -             intt =scan.nextint (); the             if(Flag[t] = =-1 ) -             { -Flag[t] = 0; -                  while(T! = 1) +                 { -                     if(t% 2 = = 1) +                     { At = (3 * t + 1)/2; at                         if(T < 101)//in the recursion of the formula, N is far greater than 100, the array is 500 still out of bounds when testing, but the data greater than 100 we can ignore -Flag[t] = 1; -                     } -                     Else -                     { -T/= 2; in                         if(T < 101)//!!! The n here may be because the last odd calculation even after/2 is still out of bounds -Flag[t] = 1; to                     } +                 } -             } the         } *          $         Booleanb =true;Panax Notoginseng          for(intj = 101; J > 1; --j) -         { the             if(Flag[j] = = 0) +             { A                 if(b) the                 { + System.out.print (j); -b =false; $                 } $                 Else -                 { -System.out.print ("" +j); the                 } -                     Wuyi             } the         } -     } Wu}

PAT b 1005. Continuation (3n+1) conjecture (25)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.