Skip to content

Instantly share code, notes, and snippets.

@gonzalezfj
Last active August 29, 2015 13:56
Show Gist options
  • Save gonzalezfj/8889811 to your computer and use it in GitHub Desktop.
Save gonzalezfj/8889811 to your computer and use it in GitHub Desktop.
// ConsoleApplication2.cpp: define el punto de entrada de la aplicación de consola.
//
#include "stdafx.h"
#define TOTAL 1000000
#define MAX(a,b) ((a) > (b) ? (a) : (b))
typedef unsigned short int usint;
usint tabla[TOTAL];
int main() {
int p, q;
int cont = 1;
int i;
for (i = 2; i < TOTAL; i <<= 1)
{
tabla[i - 1] = ++cont;
}
tabla[0] = 1;
while (scanf("%d %d", &p, &q))
{
fflush(stdin);
usint max = 0;
for (i = p; i <= q; ++i)
{
if (tabla[i - 1] == 0)
{
usint n = i;
int contador = 0;
while (n>1)
{
if (tabla[n - 1] != 0)
{
contador += tabla[n - 1];
break;
}
else
{
if (n & 1)
{
n = 3 * n + 1;
}
else
{
n >>= 1;
}
contador++;
}
}
tabla[i - 1] = contador;
}
max = MAX(max, tabla[i - 1]);
printf("-----------------MAXIMO[%d] %d %d %d\n----------------", i, p, q, max);
}
printf("%d %d %d\n", p, q, max);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment