forked from IElgohary/Uva-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path100-3n+1.cpp
executable file
·57 lines (48 loc) · 930 Bytes
/
100-3n+1.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
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <vector>
#include <stdio.h>
#include <iostream>
#include <sstream>
using namespace std;
int mx = 0;
void connect(int n, int x )
{
if ( x > mx)
mx = x;
if ( n == 1)
return;
if ( n % 2 != 0)
{
//g.arr[n-1].push_back((3*n)-1);
connect((3*n)+1 , x+1);
}else
{
//g.arr[n-1].push_back(n/2);
connect(n/2 , x+1);
}
}
int main()
{
string l ;
while(getline(cin , l) && l.length()> 0)
{
int a , b ;
istringstream os(l);
os >> a >>b;
int tmp = 0;
int m , n;
if (b < a)
{
m = b ;
n = a ;
}
else
{
m = a;
n = b;
}
mx = 0;
for ( int i = m ; i <= n ; i++)
connect(i , 1);
cout <<a << " " << b << " "<< mx<< endl;
}
}