-
Notifications
You must be signed in to change notification settings - Fork 0
/
100.cpp
60 lines (54 loc) · 788 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
100 - The 3n + 1 problem
*/
#include<bits/stdc++.h>
using namespace std;
int func(int a, int b);
int main()
{
int i,j,result;
while(scanf("%d %d",&i,&j)!=EOF)
{
result = func(i,j);
printf("%d %d %d\n",i,j,result);
}
}
int func(int a, int b)
{
int count=1,val=0,temp;
if(a>b)
{
temp =a;
a=b;
b=temp;
}
while(a<=b)
{
int x=a;
while(x!=1)
{
if(x%2==0)x=x/2;
else
x=(3*x)+1;
count++;
if(x==1)break;
}
if(count>val)
val=count;
count=1;
a++;
}
return val;
}
/*
Sample Input
1 10
100 200
201 210
900 1000
Sample Output
1 10 20
100 200 125
201 210 89
900 1000 174
*/