-
-
Save gonzalezfj/8890409 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
#define TOTAL 1000000 | |
#define MIN(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]=++cont; | |
} | |
while (cin>>p>>q) | |
{ | |
usint min = (usint)TOTAL; | |
int i; | |
for (i = p; i <= q; ++i) | |
{ | |
if(tabla[i]==0) | |
{ | |
usint n = i; | |
int contador=1; | |
while(n>=1) | |
{ | |
if(tabla[n]!=0) | |
{ | |
contador += tabla[n]; | |
} | |
else | |
{ | |
if (i & 1) | |
{ | |
n>>=1; | |
}else | |
{ | |
n=3*n+1; | |
} | |
contador++; | |
} | |
} | |
tabla[i] = contador; | |
} | |
min = MIN(min,tabla[i]); | |
} | |
cout << p << " " << q << " " << min << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment