-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumberLoopThomas.cpp
74 lines (61 loc) · 1.65 KB
/
numberLoopThomas.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/***********************************************************
* @����: 3n + 1 problem
* @����: Shawn
* @����ʱ��: 2017-11-14 20:38:17
* @���Shawnhomas
* @��ʱ��: 2017-11-14 21:05:17
* @��ע: derp
* @��Ŀ��Դ�� https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36
***********************************************************/
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
long long numberLoop(long long a, long long b)
{
long long ans = 0;
long long minNumber = min(a, b);
long long maxNumber = max(a, b);
for (long long i = minNumber; i <= maxNumber; ++i)
{
long long n = i, length = 1;
while (n != 1)
{
if (n % 2 == 0)
{
n = n / 2;
}
else
{
n = 3 * n + 1;
}
++length;
}
if (length > ans)
{
ans = length;
}
}
return ans;
}
int main()
{
ifstream fin("numberLoopShawn.in");
ofstream fout("numberLoopShawn.out");
//int minB, maxB, ans = 0, out;
//fin >> minB >> maxB;
//fout << minB << " " << maxB << " ";
while (true)
{
long long minB = 0, maxB = 0, ans = 0;
fin >> minB >> maxB;
ans = numberLoop(minB, maxB);
fout << minB << " " << maxB << " " << ans << endl;
if (fin.eof())
{
break;
}
}
return 0;
}