XXX law (Hangzhou electric oj3782)

Source: Internet
Author: User

XXX LawTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 2759 Accepted Submission (s): 2035


Problem description for a number n, if it is even, cut off n half, if it is odd, turn N to 3*n+ 1 and cut it down by half until the number becomes 1.
Please calculate how many steps it takes to change N to 1, which is a concrete example.
The input test contains multiple use cases, each containing an integer n, which indicates the end of the input when n is 0. (1<=n<=10000)
Output for each set of test cases, print a number that represents the number of steps that need to elapse, one row for each set of outputs.
Sample Input
310

Sample Output
50

SOURCE Zhejiang University Computer Postgraduate exam on the machine-2009
#include <stdio.h>int main () {int n,t;while (scanf ("%d", &n) &&n) {T=0;while (n!=1) {    if (n&1)    n= (n*3+1)/2;else    

XXX law (Hangzhou electric oj3782)

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.