Analysis of Pat computer problems in Zhejiang University 1001. conjecture that killing people is not worth the candle (3N + 1) (15)

Source: Internet
Author: User
1001. The (3N + 1) conjecture that the dead are not worth the candle (15) Time Limit 400 MS
Memory limit 32000 KB
CodeLength limit 8000 B
JudgementProgram Standard Author Chen, Yue

Callatz conjecture:

For any natural number N, if it is an even number, cut it by half; if it is an odd number, cut (3N + 1) by half. In this way, we will continue to cut down and finally get n = 1 in a certain step. Karaz announced this conjecture at the world mathematician conference in 1950. It is said that at that time, the teachers and students of Yale University were mobilized to prove this seemingly silly and naive proposition, and the results made the students unwilling to study, as a result, some people say this is a conspiracy. karaz is deliberately delaying the progress of teaching and scientific research in American mathematics ......

Today's question is not to prove caraz's conjecture, but to give a given positive integer n of no more than 1000, simply count it. How many steps (cut down) Do we need to get n = 1?

Input Format:Each test input contains one test case, that is, the value of natural number n.

Output Format:The number of steps required for the output from N to 1.

Input example:

 
3

Output example:

 
5
 
 # include 
   
     using namespace STD; int main () {int K = 0; // int N for statistics; // CIN> N; while (n> 1) {If (N % 2) N = (N * 3 + 1); N/= 2; k ++;} cout 
     
     

submit Code

View comments * the above comments only represent their personal opinions, does not represent the opinion or position of the csdn website


Related Article

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.