Problema 3n+1 em java

2 respostas
G

Pessoal eu estava fazendo um problema de uma questão que envolve uma formula assim: 3n+1.
Quando eu coloco um numero para fazer ele roda perfeito.
Mas o problema pede para fazer com dois numeros… Só que tem um detalhe! Eu não entendi muito bem o que o problema pede… vc´s tem como dar ajuda pra entender este problema. Mas não resolver.
O maior problema ficou nesta parte…

For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.

The Input
The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0.

You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j.

You can assume that no operation overflows a 32-bit integer.

The Output
For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).

na minha tradução arranhada é pegar dois numeros e fazer no algoritmo que envolve o 3n+1.

segue o end do problema.
http://acm.uva.es/p/v1/100.html

grato.
Eu ja tenho o algoritmo implementado para um numero n qualquer. tipo 22 da 16…

2 Respostas

J

Serão dadas duas entradas (i, j), você vai pegar cada numero que esteja entre i e j (maior que i e menor que j) e fazer esse calculo, e vai descobrir qual é o maior resultado…

ex.:

i = 1;
j = 10;

n = 2 --> 2
n = 3 --> 8
n = 4 --> 3
n = 5 --> 6
n = 6 --> 9
n = 7 --> 17
n = 8 --> 4
n = 9 --> 20

resultado 20

Pelo menos de acordo com o algoritmo de teste que fiz aqui, é isso mesmo.

G

por exemplo; eu coloco 1 e 10 da 20.
na minha forma de pensar foi a seguinte!!
10 - 1 = 9
n = 9 … que da 20
mas se for fazer com outros numeros tipo 200 - 100 não rola.
voce pode explicar de outra forma sua resposta? não comprendi ela.
grato.

Criado 28 de fevereiro de 2007
Ultima resposta 1 de mar. de 2007
Respostas 2
Participantes 2