-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path100.cpp
44 lines (41 loc) · 767 Bytes
/
100.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <cstdio>
using namespace std;
int CycleLength(int);
int main()
{
int i;
int j;
int iMax;
int iMin;
int iMax_length;
int iTemp_length;
while((cin >>i) && (cin >>j))
{
iMax_length=0;
iMax = (i>j)? i : j ;
iMin = (i<j)? i : j ;
for(; iMin<=iMax ; iMin++)
{
iTemp_length = CycleLength(iMin);
iMax_length = (iTemp_length > iMax_length)? iTemp_length : iMax_length;
}
printf("%d %d %d\n",i,j,iMax_length);
}
return 0;
}
int CycleLength(int n)
{
if (n == 1)
{
return 1;
}
else if ( n % 2 )
{
return 1+CycleLength(3*n+1);
}
else
{
return 1+CycleLength(n/2);
}
}