acm--Mathematics--Xiang da oj 1142--collatz conjecture

Source: Internet
Author: User


Xiang da OJ Address: http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1142



Collatz conjecture
Time limit: 8 MS Memory Limit : 1048536KB

Cauraz conjecture, also known as 3n +1 conjecture, hail conjecture, Angular valley conjecture, Hasse conjecture, Ulam conjecture, or conjecture, refers to each positive integer, If it is odd, then it is multiplied by 3 plus 1 , if it is an even number, divide it by 2 , so that the loop can eventually be Span lang= "en-US" style= "Font-family:simsun,serif" >1 .

n = 6 , According to the above-mentioned formula, we get  6→3→10→5→16→8→4→2→1  . The highest number of steps is 16 , total 8 steps. Now given any integer a and b , ask for all a≤n≤b , after how many steps to get 1 , where the highest number is.


Input

There are multiple sets of test data. One row for each set of test data, containing two positive integers 1≤a≤1000000 and a≤b≤a +. The input ends with EOF .


Output

For each set of test data, output steps and the highest number, separated by a space.


Sample Input
6 6
11 12
23 33

Sample Output
8 16
23 52
360 9232



================================ born proud of the split line ==========================




just start to see this topic is very simple, but actually this topic is very perverted, can use long long and __int64, but the output must be%I64D!


#include <stdio.h>  int main ()  {      int a,b,i;      __int64 count,max,t;      while (scanf ("%d%d", &a,&b)!=eof)      {          count=0;max=a;          for (i=a;i<=b;i++)          {                          t=i;              while (t!=1)              {                  if (t%2)                  {                      t=t*3+1;                  }                  else                  {                      t=t/2;                                      }                  if (T>max)                      max=t;                  count++;              }          }          printf ("%i64d%i64d\n", Count,max);      }      return 0;  }  



Reference Blog: http://blog.csdn.net/hnuzengchao/article/details/7585170



acm--Mathematics--Xiang da oj 1142--collatz conjecture

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.