View Code of Problem 331

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
int cal(int n)
{
	int cnt = 1;
	while (n != 1)
	{
		if (n % 2 == 0)
		{
			cnt++;
			n = n / 2;
		}
		else if (n % 2 == 1)
		{
			cnt++;
			n = 3 * n + 1;
		}
	}
	return cnt;
}
int a[10001];
int main()
{
	for (int i = 1;i <= 10000;i++)
	{
		a[i] = cal(i);
		//cout << a[i];
	}
	int c, b;
	while (cin >> c >> b)
	{
		if (c > b)
			swap(c, b);
		int max = -1;
		for (int j = c;j <= b;j++)
		{
			if (a[j] > max)
				max = a[j];
		}
		cout << c<<" "<<b<<" "<<max << endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 331