forked from xtaci/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva100.cpp
More file actions
57 lines (42 loc) · 914 Bytes
/
Copy pathuva100.cpp
File metadata and controls
57 lines (42 loc) · 914 Bytes
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 <iostream>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;
#define REP(i, a, b) \
for (int i = (int) a; i <= (int)b; i++)
int cal(int n);
int cal(int n) {
int result = 1;
while(n != 1) {
if (n%2 == 1) {
n = 3*n + 1;
n >>= 1;
result +=2;
} else {
n >>=1;
result++;
}
}
return result;
}
int main ()
{
int i, j;
while ( scanf ("%d %d", &i, &j) != EOF ) {
int temp_i = i;
int temp_j = j;
if ( i > j ) swap (i, j);
int max_cycle_length = 0;
int cycle_length;
while ( i <= j ) {
unsigned int n = i;
cycle_length = cal(n);
if ( cycle_length > max_cycle_length )
max_cycle_length = cycle_length;
i++;
}
printf ("%d %d %d\n", temp_i, temp_j, max_cycle_length);
}
return 0;
}